我在我的项目中使用了
MongoDB
一段时间。但嗯目前是MongoDB
指南针应用程序的新手。所以当我想一次删除很多文档时。
我将如何在 Mongo Compass
中执行该操作?
Compass最新稳定版本(1.16.3)不支持删除多个操作。 为此,您需要使用 mongo shell - https://docs.mongodb.com/v3.2/tutorial/remove-documents/
**** 更新****
从 1.22 开始,Compass 内置了 shell,您可以在其中运行删除许多操作。请参阅此处的文档 - https://www.mongodb.com/docs/compass/current/embedded-shell/
在使用 MongoDB Compass 搜索 shell 选项时,我发现 compass 还提供了内置 shell,可用于执行 MongoDB 命令。请查看下面我的回答以获取更多信息。
如何使用 MongoDB compass 删除 MongoDB 集合中选定的多条记录
干杯,
Compass 中的解决方法是先删除集合,然后创建同名的集合,甚至导入一些示例文档。
唯一的方法[直到版本 1.20.5] 是从 mongo-shell 执行删除命令。
以下是使用 mongo-shell 删除与过滤器匹配的多个文档的步骤和示例
mongo "mongodb+srv://cluster-name.mongodb.net/db_name" --username <uasername> --password <password>
db.users.remove( { status : "P" } )
从用户集合中删除状态字段等于“P”的所有文档