Database Manual / Reference / mongosh Methods / Bulk Operations

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

Tip

MongoDB also provides the Mongo.bulkWrite() method for performing bulk write operations.MongoDB还提供了Mongo.bulkWrite()方法来执行批量写入操作。

Description描述

Bulk.find.removeOne()

Starting in mongosh 0.12.2, Bulk.find.removeOne() is an alias for Bulk.find.deleteOne().mongosh 0.12.2开始,Bulk.find.removeOne()Bulk.find.deleteOne()的别名。

In new code, use Bulk.find.deleteOne() instead of Bulk.find.removeOne().在新代码中,使用Bulk.find.deleteOne()而不是Bulk.find.removeOne()

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