Bulk.find.removeOne()

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.removeOne()

Adds a single document remove operation to a bulk operations list. 将单个文档删除操作添加到批量操作列表。Use the Bulk.find() method to specify the condition that determines which document to remove. 使用Bulk.find()方法指定确定要删除哪个文档的条件。The Bulk.find.removeOne() limits the removal to one document. Bulk.find.removeOne()将删除限制为一个文档。To remove multiple documents, see Bulk.find.remove().要删除多个文档,请参阅Bulk.find.remove()

Example示例

The following example initializes a Bulk() operations builder for the items collection and adds two Bulk.find.removeOne() operations to the list of operations.下面的示例初始化items集合的Bulk()操作生成器,并将两个Bulk.find.removeOne()操作添加到操作列表中。

Each remove operation removes just one document: one document with the status equal to "D" and another document with the status equal to "P".每次删除操作只删除一个文档:一个status等于"D"的文档和另一个status"P"的文档。

var bulk = db.items.initializeUnorderedBulkOp();
bulk.find( { status: "D" } ).removeOne();
bulk.find( { status: "P" } ).removeOne();
bulk.execute();
←  Bulk.find.remove()Bulk.find.replaceOne() →