Bulk.find.replaceOne()

Tip

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

Description

  • Bulk.find.replaceOne()

New in version 2.6.

Adds a single document replacement operation to a bulk operationslist. Use the Bulk.find() method to specify the conditionthat determines which document to replace. TheBulk.find.replaceOne() method limits the replacement to asingle document.

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

ParameterTypeDescriptionreplacementdocumentA replacement document that completely replaces the existingdocument. Contains only field and value pairs.

The sum of the associated <query> document from theBulk.find() and the replacement document must be less thanor equal to the maximum BSON document size.

To specify an upsert for this operation, seeBulk.find.upsert().

To specify the index to use for the associatedBulk.find(), see Bulk.find.hint().

Example

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

  1. var bulk = db.items.initializeUnorderedBulkOp();
  2. bulk.find( { item: "abc123" } ).replaceOne( { item: "abc123", status: "P", points: 100 } );
  3. bulk.execute();

See also