Database Manual / Reference / mongosh Methods / Bulk Operations

Bulk.find.delete() (mongosh method方法)

Definition定义

Bulk.find.delete()

Adds a multiple document delete operation to a bulk operations list. Use the Bulk.find() method to specify the condition that determines which documents to remove.将多文档删除操作添加到批量操作列表中。使用Bulk.find()方法指定确定要删除哪些文档的条件。

Bulk.find.delete() deletes all matching documents. To remove the first matching document, see Bulk.find.deleteOne().删除所有匹配的文档。要删除第一个匹配的文档,请参阅Bulk.find.deleteOne()

Compatibility兼容性

This command is available in deployments hosted in the following environments:此命令在以下环境中托管的部署中可用:

  • MongoDB Atlas: The fully managed service for MongoDB deployments in the cloud:云中MongoDB部署的完全托管服务

Note

This command is supported in all MongoDB Atlas clusters. 所有MongoDB Atlas集群都支持此命令。For information on Atlas support for all commands, see Unsupported Commands.有关Atlas支持所有命令的信息,请参阅不支持的命令

Syntax语法

The command has the following syntax:该命令具有以下语法:

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

For details on the find() method see: Bulk.find()有关find()方法的详细信息,请参阅:Bulk.find()

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" } ).delete();
bulk.execute()

To delete only the first matching document, use Bulk.find.deleteOne() instead.要仅删除第一个匹配的文档,请改用Bulk.find.deleteOne()