Bulk.find.removeOne()
On this page本页内容
Tip
Starting in version 3.2, MongoDB also provides the 从3.2版本开始,MongoDB还提供了db.collection.bulkWrite() method for performing bulk write operations.db.collection.bulkWrite()方法来执行批量写入操作。
Description描述
Bulk.find.removeOne()-
Starting in从mongosh0.12.2,Bulk.find.removeOne()is an alias forBulk.find.deleteOne().mongosh0.12.2开始,Bulk.find.removeOne()是Bulk.find.deleteOne()的别名。In new code, use在新代码中,请使用Bulk.find.deleteOne()instead ofBulk.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()