MongoD...teView(3pm)
π MongoDB::BulkWriteView β the manual, but make it make sense π
okay so bestie, you're reading the docs for MongoDB::BulkWriteView, a Perl module that lives in the User Contributed Perl Documentation section of the manual (that's the 3pm part, iykyk). We're at version v2.2.2 and honestly? It's giving β¨bulk write operations against a query documentβ¨. Let's get into it.
πΈ NAME πΈ
MongoDB::BulkWriteView β Bulk write operations against a query document. Periodt.
π VERSION π
version v2.2.2 β that's the one, no cap.
β¨ SYNOPSIS β¨
okay so here's the vibe, all the moves you can pull. Copied exactly, bestie, every character. π
my $bulk = $collection->initialize_ordered_bulk_op;
# Update one document matching the selector
bulk->find( { a => 1 } )->update_one( { '$inc' => { x => 1 } } );
# Update all documents matching the selector
bulk->find( { a => 2 } )->update_many( { '$inc' => { x => 2 } } );
# Update all documents matching the selector, with respect to a collation
bulk->find( { a => { '$gte' => 'F' } )->collation($collation)
->update_many( { '$inc' => { x => 2 } } );
# Update all documents
bulk->find( {} )->update_many( { '$inc' => { x => 2 } } );
# Replace entire document (update with whole doc replace)
bulk->find( { a => 3 } )->replace_one( { x => 3 } );
# Update one document matching the selector or upsert
bulk->find( { a => 1 } )->upsert()->update_one( { '$inc' => { x => 1 } } );
# Update all documents matching the selector or upsert
bulk->find( { a => 2 } )->upsert()->update_many( { '$inc' => { x => 2 } } );
# Replaces a single document matching the selector or upsert
bulk->find( { a => 3 } )->upsert()->replace_one( { x => 3 } );
# Remove a single document matching the selector
bulk->find( { a => 4 } )->delete_one();
# Remove all documents matching the selector
bulk->find( { a => 5 } )->delete_many();
# Update any arrays with the matching filter
bulk->find( {} )->arrayFilters([ { 'i.b' => 1 } ])->update_many( { '$set' => { 'y.$[i].b' => 2 } } );
# Remove all documents matching the selector, with respect to a collation
bulk->find( { a => { '$gte' => 'F' } )->collation($collation)->delete_many();
# Remove all documents
bulk->find( {} )->delete_many();
π¦ DESCRIPTION π¦
So like, this class is your girl for specifying write operations that are constrained by a query document. You're not just blindly writing β you're writing at a specific set of docs. Main character energy, honestly.
Wanna instantiate a MongoDB::BulkWriteView? Use the find method from MongoDB::BulkWrite. That's the doorway, babe. πͺβ¨
Now for the important bit, and I need you to focus: except for arrayFilters, collation and upsert, every single method returns an empty return on success, and it'll throw an exception on error. So don't be out here checking for a truthy return value, okay? That's not the vibe. π
π«Ά METHODS π«Ά
π arrayFilters
$bulk->arrayFilters( $array_filters )->update_many( $modification );
Hands you back a new MongoDB::BulkWriteView object, and this one's got your specified arrayFilter loaded up so it knows which array elements to modify for an update operation on an array field. Obsessed. β¨
π collation
$bulk->collation( $collation )->delete_one;
Returns a new MongoDB::BulkWriteView object where your specified collation gets used to figure out which documents match the query document. And the tea? β You can specify a collation for any deletion, replacement, or update. Any of them. Slay.
π delete_many
$bulk->delete_many;
Removes all documents matching the query document. All of them. Gone. π«‘
π delete_one
$bulk->delete_one;
Removes a single document matching the query document. Just the one, bestie.
π replace_one
$bulk->replace_one( $doc );
Replaces the document matching the query document. Important caveat, don't skip this: the document you're replacing with must not have any keys that begin with a dollar sign, "$". That's a hard no. π«
π₯ update_many
$bulk->update_many( $modification );
Updates all documents matching the query document. And heads up: the modification document must have all its keys begin with a dollar sign, "$". Every single key. Don't test her.
β update_one
$bulk->update_one( $modification );
Updates a single document matching the query document. Same rule applies, no exceptions: the modification document must have all its keys begin with a dollar sign, "$".
π§ upsert
$bulk->upsert->replace_one( $doc );
Returns a new MongoDB::BulkWriteView object that will treat every update, update_one or replace_one operation as an upsert operation. It's giving glow-up for your writes. π
π AUTHORS π
The icons who made this:
- David Golden
<david@mongodb.com> - Rassi
<rassi@mongodb.com> - Mike Friedman
<friedo@friedo.com> - Kristina Chodorow
<k.chodorow@gmail.com> - Florian Ragwitz
<rafl@debian.org>
πΈ COPYRIGHT AND LICENSE πΈ
This software is Copyright (c) 2020 by MongoDB, Inc. π«Ά
This is free software, licensed under:
The Apache License, Version 2.0, January 2004
ngl bestie, that's the whole page. Every flag, every method, every caveat β all present and accounted for. π―
and that's a wrap, gorgeous π this page came from the User Contributed Perl Documentation for perl v5.40.1, dated 2025-04-03, so if you ever need to cite your sources, that's the receipt. mwah πβ¨
π¦ where this page comes from
- debian trixie: libmongodb-perl 2.2.2-3 Β· Apache-2.0
- ubuntu resolute: libmongodb-perl 2.2.2-3 Β· Apache-2.0
- ubuntu stonking: libmongodb-perl 2.2.2-3 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms