Bulk.find()

On this page本页内容

Tip

Starting in version 3.2, MongoDB also provides the db.collection.bulkWrite() method for performing bulk write operations.从3.2版开始,MongoDB还提供了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 Bulk.find() method to specify a condition for their respective actions:删除操作和更新操作使用Bulk.find()方法为各自的操作指定条件:

var bulk = db.items.initializeUnorderedBulkOp();
bulk.find( { status: "D" } ).remove();
bulk.find( { status: "P" } ).update( { $set: { points: 0 } } )
bulk.execute();