MongoDB - Delete Database

MongoDB - Delete Database

dropDatabase() method

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

Syntax

The basic syntax of the dropDatabase() command is as follows:

db.dropDatabase()

This will remove the selected database. If you haven't selected any database, it will remove the "test" database by default.

example

First, check the list of available databases with the show dbs command .

> show dbs
 local 0.78125GB 
mydb        0.23012GB 
test        0.23012GB >      

If you want to drop the new database <mydb> , the dropDatabase() command would look like this:

> use mydb
switched to db mydb
> db.dropDatabase() >{ "dropped" : "mydb" , "ok" : 1 } >
       

Now check the list of databases.