Bulk.find()
On this page本页内容
Starting in version 3.2, MongoDB also provides the 从3.2版本开始,MongoDB还提供了db.collection.bulkWrite()
method for performing bulk write operations.db.collection.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描述query
document Specifies a query condition using Query Selectors 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()
与以下写入操作一起使用:
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();