简体   繁体   English

一次删除多个文档 mongodb 图集

[英]delete multiple documents at once mongodb atlas

I am only to delete one record at a time in Mongodb cloud db (Atlas).我只能在 Mongodb 云数据库(Atlas)中一次删除一条记录。 I have 60 records to delete and it is painful.我有 60 条记录要删除,这很痛苦。 I do not see an obvious way to delete multiple records at once.我看不到一次删除多条记录的明显方法。 Is there a simple way to do this?有没有一种简单的方法可以做到这一点?

You actually can't bulk delete in MongoDB Atlas.您实际上无法在 MongoDB Atlas 中进行批量删除。 See MongoDB Atlas info on the filter section AKA Data Explorer .请参阅过滤器部分 AKA Data Explorer 上的 MongoDB Atlas 信息 However you can run standard queries, like find, remove once you connect to the database using your Atlas credentials.但是,一旦使用 Atlas 凭据连接到数据库,您就可以运行标准查询,例如 find、remove。

At the clusters view, click connect on the cluster with the collection you would like to query/modify.在集群视图中,单击连接您要查询/修改的集合的集群。 Then follow the UI to get your connection string using Mongo Shell.然后按照 UI 使用 Mongo Shell 获取连接字符串。 If you need a GUI way to delete, you may consider Mongo Compass.如果需要GUI方式删除,可以考虑Mongo Compass。 Atlas also provides instructions how to connect via Compass on the same page. Atlas 还在同一页面上提供了如何通过 Compass 进行连接的说明。

连接菜单

You can use $multi=true in remove method of the collection in mongo shell您可以在 mongo shell 中的集合的 remove 方法中使用$multi=true

db.collectionName.remove({where condition}, {$multi:true})

Will delete all the records matching the conditions.将删除所有符合条件的记录。

If you are using the JPA or mongo-data repository in any language then you might have below methods:如果您使用任何语言的 JPA 或 mongo-data 存储库,那么您可能有以下方法:

 deleteAllByColumnName(ColumnNameValue)

or或者

 deleteAll()

in the interface class, you just need to use the dao.deleteAll() method.在接口类中,你只需要使用 dao.deleteAll() 方法。

For more documents on Repository Delete Queries please check here有关存储库删除查询的更多文档,请查看此处

I normally use mLab which is owned by MongoDB.我通常使用 MongoDB 拥有的 mLab。 There is an option in there for deleteing all documents.那里有一个用于删除所有文档的选项。

mLab.com实验室

实验室

您可以使用类似于 Compass 但具有删除功能的 Robomongo,因此您可以使用这样的查询:deleteMany({name: "dang"}) https://robomongo.org/

If you don't want to keep any of the documents inside a collection you can just drop the entire collection through mongodb atlas app.如果您不想将任何文档保留在集合中,您可以通过 mongodb atlas 应用程序删除整个集合 That will delete all the documents inside your collection . That will delete all the documents inside your collection Don't worry the collection will get created on its own when you create a document.不用担心当您创建文档时集合会自行创建。 I find this way more convenient than installing the mongodb shell and then running the remove query.我发现这种方式比安装 mongodb shell 然后运行删除查询更方便。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM