Bulk.find()

Tip

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

Description

  • Bulk.find()

New in version 2.6.

Specifies a query condition for an update or a remove operation.

Bulk.find() accepts the following parameter:

ParameterTypeDescriptionquerydocumentSpecifies a query condition using Query Selectors to selectdocuments for an update or a remove operation. To specify all documents,use an empty document {}.

With update operations, the sum of the query document and the updatedocument must be less than or equal to the maximum BSONdocument size.

With remove operations, the query document must be less than or equalto the maximum BSON document size.

Use Bulk.find() with the following write operations:

Example

The following example initializes a Bulk() operations builderfor the items collection and adds a remove operation and an updateoperation to the list of operations. The remove operation and theupdate operation use the Bulk.find() method to specify acondition for their respective actions:

  1. var bulk = db.items.initializeUnorderedBulkOp();
  2. bulk.find( { status: "D" } ).remove();
  3. bulk.find( { status: "P" } ).update( { $set: { points: 0 } } )
  4. bulk.execute();

See also