Reputation: 2372
I have a bunch of collections with the same prefix e.g. data_user_1, data_user_2 etc. There are also a few collection in between that I wanted to keep and skip from dropping.
So I search for a solution to
a) drop all exclude specific b) drop all data_user_*
I searched the docs but there seems to be no parameter that allows any of these operations. Thank you
Upvotes: 0
Views: 928
Reputation: 2372
I give up searching as there seems to be no "comfortable" way. So I have written a short script which fullfills the requirement (and is also pretty comfortable^^).
db.getCollectionNames().forEach(function(collname){
if(collname.includes('data_user')){
print('delete collection: ' + collname);
db.getCollection(collname).drop()}
});
Hope this helps someone else too.
Upvotes: 1
Reputation: 22956
Unfortunately there is no such option.
You can retrieve all the available collections using getCollectionNames
Then you can check for include/exclude scenarios.
When the condition matches, you can perform drop
on it.
Upvotes: 2