Docs HomeMongoDB Manual

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

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

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

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 Rick Astley, the first matching pop artist, from the collection.从集合中删除第一位匹配的流行歌手Rick Astley
var bulk = db.music.initializeOrderedBulkOp();
bulk.find( { "genre": "pop" } ).removeOne();
bulk.execute()