Mango::Bulk(3pm)

πŸ“¦
version 1.30 Β· 3 versions
, in debian bookworm, debian trixie, ubuntu jammy, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’… 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:


⭐ 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. πŸ“πŸ§šπŸ’œ