Navigation
This is an upcoming (i.e. in progress) version of the manual.

Bulk.find.updateOne()

Tip

Starting in version 3.2, MongoDB also provides the db.collection.bulkWrite() method for performing bulk write operations.

Description

Bulk.find.updateOne(<update>)

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 that determines which document to update. The Bulk.find.updateOne() method limits the update to a single document. To update multiple documents, see Bulk.find.update().

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

Parameter Type Description
update document

The modifications to apply.

The value can be either:

For more information on the update modification parameter, see the db.collection.updateOne reference page.

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

Behavior

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

{
  $set: { status: "D" },
  $inc: { points: 2 }
}

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

Example

The following example initializes a Bulk() operations builder for the items collection, and adds various updateOne operations to the list of operations.

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