MongoDB - Drop a Database
To drop a collection in MongoDB, use either the db.dropDatabase()
method, or the dropDatabase
command.
In MongoDB, you can drop a database by switching to that database and running either the db.dropDatabase()
method or the dropDatabase
command.
The db.dropDatabase()
Method
Here, we'll use db.dropDatabase()
method to drop the current database.
First, let's check our list of databases:
> show databases local 0.000GB music 0.000GB test 0.005GB
Check out list of databases again:
> show databases local 0.000GB test 0.005GB
The music database is no longer with us.
The dropDatabase
Command
You can also use the dropDatabase
command to do the same thing.
Resulting message:
{ "dropped" : "test", "ok" : 1 }
And our list of databases has shrunk again:
> show databases local 0.000GB