提示
MongoDB 还提供了 Mongo.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: The fully managed service for MongoDB deployments in the cloud
注意
This command is supported in all MongoDB Atlas clusters. For information on Atlas support for all commands, see Unsupported Commands.
例子
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();