How to delete lots of mongodb collections at once?

前端 未结 5 543
刺人心
刺人心 2020-12-09 04:06

There are a lot of mongodb collections in my database that I need to delete. They all have similar names, and it would be easy to delete them if only wildcard characters cou

5条回答
  •  隐瞒了意图╮
    2020-12-09 04:40

    You can delete all the collections using the following command.

    > use database_name;
    
    > db.getCollectionNames().forEach(function(c) {
        if(c != 'system.indexes') { 
            db.getCollection(c).drop();
        }
      });
    

提交回复
热议问题