Bulk.find.updateOne()

Tip

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

Description

  • Bulk.find.updateOne()

New in version 2.6.

Adds a single document update operation to a bulk operations list.

Use the Bulk.find() method to specify the condition thatdetermines which document to update. TheBulk.find.updateOne() method limits the update to a singledocument. To update multiple documents, seeBulk.find.update().

Bulk.find.updateOne() 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 beless than or equal to the maximum BSON document size.

Behavior

If the <update> document contains only update operator expressions, as in:

  1. {
  2. $set: { status: "D" },
  3. $inc: { points: 2 }
  4. }

Then, Bulk.find.updateOne() updates only the correspondingfields, status and points, in the document.

Example

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

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

See also