On this page本页内容
Tip
Starting in version 3.2, MongoDB also provides the db.collection.bulkWrite()
method for performing bulk write operations.
Bulk.find.
update
(<update>)¶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:
update | document or pipeline | The modifications to apply. Can be one of the following:
For more information on the update modification parameter, see the The sum of the associated |
Bulk.find.upsert()
. With Bulk.find.upsert()
, if no documents match the Bulk.find()
query condition, the update operation inserts only a single document.Bulk.find.arrayFilters()
.Bulk.find()
, see Bulk.find.hint()
.Bulk.find.replaceOne()
.The following example initializes a Bulk()
operations builder for the items
collection, and adds various multi
update operations to the list of operations.
Starting in version 4.2, update methods can accept an aggregation pipeline. For example, the following uses:
$set
stage which can provide similar behavior to the $set
update operator expression,NOW
, which resolves to the current datetime and can provide similar behavior to a $currentDate
update operator expression. To access aggregation variables, prefix the variable with double dollar signs $$
and enclose in quotes.