Definition定义
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()方法指定决定删除哪个文档的条件。Bulk.find.deleteOne()only deletes the first matching document. To remove multiple documents, see仅删除第一个匹配的文档。要删除多个文档,请参阅Bulk.find.delete().Bulk.find.delete()。
Syntax语法
The command has the following syntax:该命令具有以下语法:
Bulk.find( <filter document> ).deleteOne()
For details on the find() method see: Bulk.find()
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支持所有命令的信息,请参阅不支持的命令。
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" } ).deleteOne();
bulk.execute()
To delete all 要删除所有"pop" music, use Bulk.find.delete() instead."pop"音乐,请使用Bulk.find.delete()。