Browse By

How to drop all MongoDB databases

mongo-db-logo
The title of the article is pretty much self-explanatory. So the easiest way I found to drop all your MongoDB databases from mongo CLI is to run this simple command which actually what it does is it goes through the result of getDBNames function and for each DB runs the .dropDatabase function.

mongo --quiet --eval 'db.getMongo().getDBNames().forEach(function(i){db.getSiblingDB(i).dropDatabase()})'

 

Leave a Reply

Your email address will not be published. Required fields are marked *