Bulk.find.replaceOne()

On this page本页内容

Tip提示

Starting in version 3.2, MongoDB also provides the db.collection.bulkWrite() method for performing bulk write operations.从3.2版开始,MongoDB还提供了用于执行批量写入操作的db.collection.bulkWrite()方法。

Description描述

Bulk.find.replaceOne(<document>)

Adds a single document replacement operation to a bulk operations list. 将单个文档替换操作添加到批量操作列表。Use the Bulk.find() method to specify the condition that determines which document to replace. 使用Bulk.find()方法指定确定要替换哪个文档的条件。The Bulk.find.replaceOne() method limits the replacement to a single document.Bulk.find.replaceOne()方法将替换限制为单个文档。

Bulk.find.replaceOne() accepts the following parameter:接受以下参数:

Parameter参数Type类型Description描述
replacementdocument

A replacement document that completely replaces the existing document. 完全替换现有文档的替换文档。Contains only field and value pairs.仅包含字段和值对。

The sum of the associated <query> document from the Bulk.find() and the replacement document must be less than or equal to the maximum BSON document size.Bulk.find()中关联的<query>文档和替换文档的总和必须小于或等于最大BSON文档大小

To specify an upsert for this operation, see Bulk.find.upsert().要为此操作指定upsert,请参阅Bulk.find.upsert()

To specify the index to use for the associated Bulk.find(), see Bulk.find.hint().要指定用于关联Bulk.find()的索引,请参阅Bulk.find.hint()

Example示例

The following example initializes a Bulk() operations builder for the items collection, and adds various replaceOne() operations to the list of operations.下面的示例初始化items集合的Bulk()操作生成器,并将各种replaceOne()操作添加到操作列表中。

var bulk = db.items.initializeUnorderedBulkOp();
bulk.find( { item: "abc123" } ).replaceOne( { item: "abc123", status: "P", points: 100 } );
bulk.execute();
←  Bulk.find.removeOne()Bulk.find.updateOne() →