How to remove document from all collections in Mongo database

坚强是说给别人听的谎言 提交于 2019-12-04 19:27:14

Use the method db.getCollectionNames() to get a list of all the collections in your database, iterate the list using the JavaScript's forEach() method to remove the document from each collection:

db.getCollectionNames().forEach(function (col) {
    db.getCollection(col).remove({domain_id : '123'})
});

Unfortunately, Mondo doesn't allow for linking collections. So, you do have to do it for each separate collection.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!