MongoDB Drop Database

In this post, we will see how to drop a database using the MongoDB command.

The dropDatabase() Method

MongoDB db.dropDatabase() command is used to drop a existing database.


The basic syntax of dropDatabase() command is as follows −
This will delete the selected database. If you have not selected any database, then it will delete the default 'test' database.


First, check the list of available databases by using the command, show dbs.
> show dbs;
admin   0.000GB
config  0.000GB
local   0.000GB
Let's first create a new database with the following command:
> use mydb
switched to db mydb
Now, let's drop this database with dropDatabase() command:
> db.dropDatabase()
{ "dropped" : "mydb", "ok" : 1 }
Now let's use dbs command to show all databases:
> show dbs;
admin   0.000GB
config  0.000GB
local   0.000GB


The below diagram shows the summary of all the commands used in this post:

Free Spring Boot Tutorial | Full In-depth Course | Learn Spring Boot in 10 Hours

Watch this course on YouTube at Spring Boot Tutorial | Fee 10 Hours Full Course