Bulk.find.update()

Tip

Starting in version 3.2, MongoDB also provides thedb.collection.bulkWrite() method for performing bulkwrite operations.

Description

  • Bulk.find.update()

New in version 2.6.

Adds a multi update operation to a bulk operations list. Themethod updates specific fields in existing documents.

Use the Bulk.find() method to specify the condition thatdetermines which documents to update. TheBulk.find.update() method updates all matching documents.To specify a single document update, seeBulk.find.updateOne().

Bulk.find.update() accepts the following parameter:

ParameterTypeDescriptionupdatedocumentThe modifications to apply.

The value can be either:

The sum of the associated <query> document from theBulk.find() and the update document must be less than orequal to the maximum BSON document size.

Example

The following example initializes a Bulk() operations builderfor the items collection, and adds various multi updateoperations to the list of operations.

  1. var bulk = db.items.initializeUnorderedBulkOp();
  2. bulk.find( { status: "D" } ).update( { $set: { status: "I", points: "0" } } );
  3. bulk.find( { item: null } ).update( { $set: { item: "TBD" } } );
  4. bulk.execute();

See also