Docs 菜单

Bulk.find.deleteOne()

Bulk.find.deleteOne()

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.deleteOne() only deletes the first matching document. To remove multiple documents, see Bulk.find.delete().

该命令具有以下语法:

Bulk.find( <filter document> ).deleteOne()

有关 find() 方法的详细信息,请参阅:Bulk.find()

此命令可用于以下环境中托管的部署:

注意

所有 MongoDB Atlas 集群都支持此命令。有关 Atlas 对所有命令的支持的信息,请参阅不支持的命令

创建 music 集合:

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

如下示例:

  • 初始化 Bulk() 操作构建器。

  • 搜索类型 pop

  • 删除 Rick Astley, the first matching pop artist, from the collection.

var bulk = db.music.initializeOrderedBulkOp();
bulk.find( { "genre": "pop" } ).deleteOne();
bulk.execute()

To delete all "pop" music, use Bulk.find.delete() instead.