Delete the database MongoDB

grammar

MongoDB database delete syntax is as follows:

db.dropDatabase()

Delete the current database, the default for the test, you can use db command to view the current database name.

Examples

The following example we removed the database w3resource.

First, check all databases:

> show dbs
local   0.078GB
w3resource  0.078GB
test    0.078GB

Then we switch to the database w3resource:

> use w3resource
switched to db w3resource
> 

Delete command:

> db.dropDatabase()
{ "dropped" : "w3resource", "ok" : 1 }

Finally, we show dbs command through the database deleted successfully:

> show dbs
local  0.078GB
test   0.078GB
> 

Delete Collection

Collection delete syntax is as follows:

db.collection.drop()