MongoDB: Drop Database

How to drop an existing Database in MongoDB? 

In MongoDB, the syntax to drop Database is as follows:

db.dropDatabase()

The command will delete the Database in which you are, at the time of deletion. To check the current database you can use the following command:

db;

Example

Now, let's first execute db command and check the name of the current database:

drop database mongodb1

So, currently, the Database is MyDB. Well, this is the same Database which we want to drop. So command to drop this Database will be as follows:

 db.dropDatabase();

Output:  

drop database mongodb2    

NOTE: It is a healthy practice to follow the db command before dropping any Database. Dropping a database can drop entire values stored in it. However, following the db command will confirm, whether you are in the same database that needs to be deleted.