How to delete lots of mongodb collections at once?

前端 未结 5 509
刺人心
刺人心 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:58

    # Delete Particular Collections From MongoDB
    
    > use database_name
    
    > delete_collection_list = ["collection1", "collection2", "collection3", "collection4", "collection5", "collection6"]
    
    > delete_collection_list.forEach( function (collection) {
        if (db.getCollectionNames().indexOf(collection)>=0) {
            db.getCollection(collection).drop();
            print("Deleted Collection: "+ collection);
        }
      })
    

提交回复
热议问题