MongoDB – Drop database

The dropDatabase command drops the current database, deleting the associated data files.

Different methods to drop database

Method 1:

1. select the database which you want to delete
>use < database name >
2. Then issue the below command

Method 2:

1. Define the name of the database
> var dbname=”users”
2. Issue the below command
> Mongo().getDB(dbname).dropDatabase()
{ “dropped” : “users”, “ok” : 1 }


Dropping all the databases

*****Please make a copy before deleting anything****

The first command gives you a list of dbs ‘AA’ and ‘PP’ and the second one using cursor loop through all the database and drop the databases

>db.getMongo().getDBs()[“databases”].forEach(function(dbname){ var db1=db.getMongo().getDB(; print (db1);});
> db.getMongo().getDBs()[“databases”].forEach(function(dbname){ db.getMongo().getDB(;});
> show dbs


About Prashanth Jayaram

DB Technologist, Author, Blogger, Service Delivery Manager at CTS, Automation Expert, Technet WIKI Ninja, MVB and Powershell Geek My Profile: jayaram/ Connect Me: Twitter @prashantjayaram GMAIL The articles are published in:
This entry was posted in MongoDB and tagged , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s