Mango::Bulk(3pm)
π Mango::Bulk β the whole vibe
okay so bestie, welcome to Mango::Bulk, a Perl module living its best life in the User Contributed Perl Documentation section of your man pages. it's giving "MongoDB bulk operations" and honestly? iconic.
β¨ NAME β¨
Mango::Bulk β MongoDB bulk operations. that's the whole name, that's the whole point, no notes. π₯
πΈ SYNOPSIS πΈ
here's the look, bestie, copy it exactly:
use Mango::Bulk;
my $bulk = Mango::Bulk->new(collection => $collection);
$bulk->insert({foo => 'bar'})->insert({foo => 'baz'})->execute;
see how it just chains? insert, insert, execute, done. method chaining is main character energy fr fr. π
π¦ DESCRIPTION π¦
Mango::Bulk is a container for MongoDB bulk operations. the way that it works is: you pile up all your operations, and it automatically groups them so they don't exceed max_bson_size in Mango. like, it does the math for you so you don't have to. obsessed. β¨
π ATTRIBUTES π
Mango::Bulk implements the following attributes. yes, following. as in, these ones, right here:
collection
my $collection = $bulk->collection;
$bulk = $bulk->collection(Mango::Collection->new);
this is the Mango::Collection object that this bulk operation belongs to. every bulk op has a home, and this is hers. π
ordered
my $bool = $bulk->ordered;
$bulk = $bulk->ordered($bool);
bulk operations are ordered. it defaults to a true value, so if you don't touch it, she's ordered. periodt.
π METHODS π
Mango::Bulk inherits all methods from Mojo::Base (free stuff, love that for her) and implements the following new ones:
execute
my $results = $bulk->execute;
execute the bulk operations. literally run them. πββοΈ
you can also append a callback to perform the operation non-blocking:
$bulk->execute(sub {
my ($bulk, $err, $results) = @_;
...
});
Mojo::IOLoop->start unless Mojo::IOLoop->is_running;
so you hand it a sub, it hands you back $bulk, $err and $results, and you go about your business. that Mojo::IOLoop->start unless Mojo::IOLoop->is_running; line is doing the heavy lifting so your non-blocking vibe actually blocks long enough to finish. π«Ά
find
$bulk = $bulk->find({foo => 'bar'});
query for the next update or remove operation. it's setting up the target for whatever comes next, iykyk.
insert
$bulk = $bulk->insert({foo => 'bar'});
insert a document. one document. into the pile. π
remove
$bulk = $bulk->remove;
remove multiple documents. plural. she's not being subtle about it.
remove_one
$bulk = $bulk->remove_one;
remove one document. singular. exactly one. no more, no less. π
update
$bulk = $bulk->update({foo => 'bar'});
update multiple documents. again with the plural. she contains multitudes. π₯
update_one
$bulk = $bulk->update_one({foo => 'baz'});
update one document. and yes, the example here uses {foo => 'baz'}, not {foo => 'bar'}, because the manpage said so and we do not edit the manpage. π
upsert
$bulk = $bulk->upsert;
the next update operation will be an "upsert". it's a little flag you raise, and then the next update is like "say less". π©
π SEE ALSO π
go read these too, bestie, they're part of the lore:
- Mango
- Mojolicious::Guides
- <http://mojolicio.us>
β heads up: this page came to you from perl v5.30.3 and it was dated 2020-06-05. thank you for coming to my ted talk, drink some water, hydrate, and go execute your bulk operations responsibly. ππ§π
π¦ where this page comes from
- debian bookworm: libmango-perl 1.30-2 Β· Artistic-2.0
- debian trixie: libmango-perl 1.30-2 Β· Artistic-2.0
- ubuntu jammy: libmango-perl 1.30-2 Β· Artistic-2.0
- ubuntu noble: libmango-perl 1.30-2 Β· Artistic-2.0
- ubuntu resolute: libmango-perl 1.30-2 Β· Artistic-2.0
- ubuntu stonking: libmango-perl 1.30-2 Β· Artistic-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms