Docs HomeMongoDB Manual

Bulk.find.remove()

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

Starting in mongosh 0.12.2, Bulk.find.remove() is an alias for Bulk.find.delete().mongosh 0.12.2开始,Bulk.find.remove()Bulk.find.delete()的别名。

In new code, use Bulk.find.delete() instead of Bulk.find.remove().在新代码中,请使用Bulk.find.delete()而不是Bulk.find.remove()

Example实例

Create the music collection:创建music集合:

db.music.insertMany( [
{ artist: "DOA", genre: "punk" },
{ artist: "Rick Astley", genre: "pop" },
{ artist: "Black Flag", genre: "punk" },
{ artist: "Justin Bieber", genre: "pop" }
] )

The following example:以下示例:

  • Initializes a Bulk() operations builder.初始化Bulk()操作生成器。
  • Searches for the genre pop.搜索pop音乐类型。
  • Deletes pop music from the collection.从集合中删除pop音乐。
var bulk = db.music.initializeOrderedBulkOp();
bulk.find( { "genre": "pop" } ).remove();
bulk.execute()