- Reference >
- mongo Shell Methods >
- Bulk Operation Methods >
- Bulk.find.update()
Bulk.find.update()¶
Description¶
- Bulk.find.update(<update>)¶
2.6 新版功能.
Adds a multi update operation to a bulk operations list. The method updates specific fields in existing documents.
Use the Bulk.find() method to specify the condition that determines which documents to update. The Bulk.find.update() method updates all matching documents. To specify a single document update, see Bulk.find.updateOne().
Bulk.find.update() accepts the following parameter:
Parameter Type Description update document Specifies the fields to update. Only contains update operator expressions.
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.
To specify upsert: true for this operation, see Bulk.find.upsert(). With Bulk.find.upsert(), if no documents match the Bulk.find() query condition, the update operation inserts only a single document.
Example¶
The following example initializes a Bulk() operations builder for the items collection, and adds various multi update operations to the list of operations.
var bulk = db.items.initializeUnorderedBulkOp();
bulk.find( { status: "D" } ).update( { $set: { status: "I", points: "0" } } );
bulk.find( { item: null } ).update( { $set: { item: "TBD" } } );
bulk.execute();