提示
MongoDB 还提供了 db.collection.bulkWrite() 方法用于执行批量写入操作。
说明
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.replaceOne()接受以下参数:Parameter类型说明replacement文档
完全替换现有文档的替换文档。 仅包含字段和值对。
来自
Bulk.find()的关联<query>文档与替换文档的总和必须小于或等于最大 BSON 文档大小。要为此操作指定更新或插入,请参阅
Bulk.find.upsert()。要指定相关
Bulk.find()的索引,请参阅Bulk.find.hint()。
兼容性
此命令可用于以下环境中托管的部署:
- MongoDB Atlas:用于云中 MongoDB 部署的完全托管服务
注意
所有 MongoDB Atlas 集群都支持此命令。有关 Atlas 对所有命令的支持的信息,请参阅不支持的命令。
例子
The following example initializes a Bulk() operations builder for the items collection, and adds various replaceOne() operations to the list of operations.
var bulk = db.items.initializeUnorderedBulkOp(); bulk.find( { item: "abc123" } ).replaceOne( { item: "abc123", status: "P", points: 100 } ); bulk.execute();