OPTIONS

Bulk.execute()

Description

Bulk.execute()

New in version 2.6.

Executes the list of operations built by the Bulk() operations builder.

Bulk.execute() accepts the following parameter:

Parameter Type Description
writeConcern document Optional. Write concern document for the bulk operation as a whole. Omit to use default. For a standalone mongod server, the write concern defaults to { w: 1 }. With a replica set, the default write concern for a mongod server is set as a replica set configuration option.
Returns:A BulkWriteResult object that contains the status of the operation.

After execution, you cannot re-execute the Bulk() object without reinitializing. See db.collection.initializeUnorderedBulkOp() and db.collection.initializeOrderedBulkOp().

Example

The following initializes a Bulk() operations builder on the items collection, adds a series of write operations, and executes the operations:

var bulk = db.items.initializeOrderedBulkOp();
bulk.insert( { item: "abc123", status: "A", defaultQty: 500, points: 5 } );
bulk.insert( { item: "ijk123", status: "A", defaultQty: 100, points: 10 } );
bulk.find( { status: "D" } ).removeOne();
bulk.find( { status: "D" } ).update( { $set: { points: 0 } } );
bulk.execute();

The operation returns the following BulkWriteResult() object:

BulkWriteResult({
   "writeErrors" : [ ],
   "writeConcernErrors" : [ ],
   "nInserted" : 2,
   "nUpserted" : 0,
   "nMatched" : 3,
   "nModified" : 3,
   "nRemoved" : 1,
   "upserted" : [ ]
})

For details on the return object, see BulkWriteResult().

See

Bulk() for a listing of methods available for bulk operations.