Tip
MongoDB also provides the MongoDB还提供了Mongo.bulkWrite() method for performing bulk write operations.Mongo.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. TheBulk.find.replaceOne()method limits the replacement to a single document.Bulk.find()方法指定确定替换哪个文档的条件。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 theBulk.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要为此操作指定upsert,请参阅Bulk.find.upsert().Bulk.find.upsert()。To specify the index to use for the associated要指定用于关联的Bulk.find(), seeBulk.find.hint().Bulk.find()的索引,请参阅Bulk.find.hint()。
Compatibility兼容性
This command is available in deployments hosted in the following environments:此命令在以下环境中托管的部署中可用:
- MongoDB Atlas
: The fully managed service for MongoDB deployments in the cloud:云中MongoDB部署的完全托管服务
Note
This command is supported in all MongoDB Atlas clusters. 所有MongoDB Atlas集群都支持此命令。For information on Atlas support for all commands, see Unsupported Commands.有关Atlas支持所有命令的信息,请参阅不支持的命令。
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();