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()
方法。
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()
。
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();