Tip
MongoDB also provides the MongoDB还提供了Mongo.bulkWrite() method for performing bulk write operations.Mongo.bulkWrite()方法来执行批量写入操作。
Description描述
Bulk.find(<query>)Specifies a query condition for an update or a remove operation.指定更新或删除操作的查询条件。Bulk.find()accepts the following parameter:接受以下参数:Parameter参数Type类型Description描述querydocument文档Specifies a query condition using Query Predicates to select documents for an update or a remove operation.使用查询谓词指定查询条件,以选择文档进行更新或删除操作。To specify all documents, use an empty document若要指定所有文档,请使用空文档{}.{}。With update operations, the sum of the query document and the update document must be less than or equal to the maximum BSON document size.使用更新操作时,查询文档和更新文档的总和必须小于或等于BSON文档的最大大小。With remove operations, the query document must be less than or equal to the maximum BSON document size.使用删除操作时,查询文档必须小于或等于BSON文档的最大大小。Use将Bulk.find()with the following write operations:Bulk.find()与以下写入操作一起使用:
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 a remove operation and an update operation to the list of operations. items集合初始化Bulk()操作生成器,并将删除操作和更新操作添加到操作列表中。The remove operation and the update operation use the remove操作和update操作使用Bulk.find() method to specify a condition for their respective actions:Bulk.find()方法为各自的操作指定条件:
var bulk = db.items.initializeUnorderedBulkOp();
bulk.find( { status: "D" } ).delete();
bulk.find( { status: "P" } ).update( { $set: { points: 0 } } )
bulk.execute();