MongoD...teView(3pm)

πŸ“¦
version 2.2.2 Β· 5 versions
, in debian trixie, ubuntu resolute, ubuntu stonking

πŸ’– 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>

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