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, seeBulk.find.delete()
.
语法
该命令具有以下语法:
Bulk.find( <filter document> ).deleteOne()
有关 find()
方法的详细信息,请参阅:Bulk.find()
兼容性
此命令可用于以下环境中托管的部署:
MongoDB Atlas:用于云中 MongoDB 部署的完全托管服务
注意
所有 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.