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 could be used. But it doesn't look like they can.
Is there a way to select a bunch of collections at once to delete them?
In MongoDB, you are allowed to delete the existing documents from the collection using db. collection. deleteMany() method. This method deletes multiple documents from the collection according to the filter.
MongoDB's db. collection. drop() is used to drop a collection from the database.
To delete a MongoDB Collection, use db. collection. drop() command.
You actually can't bulk delete in MongoDB Atlas. See MongoDB Atlas info on the filter section AKA Data Explorer. However you can run standard queries, like find, remove once you connect to the database using your Atlas credentials.
For regex you can use string.match
db.getCollectionNames().forEach(function(c) { if(!c.match("^system.indexes")) { db.getCollection(c).drop(); } });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With