Delete Database in MongoDB

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

DropDatabase () method in MongoDB

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

Syntax

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

 db . dropDatabase () 

This command will delete the selected database. If you do not select any database, it will delete the default test database.

For example

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

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

If you want to delete the new database mydb , then the dropDatabase () command will be as follows:

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

Now, try checking the list of databases.

 > show dbs local 0.78125GB test 0.23012GB > 

According to Tutorialspoint

Previous post: Create Database in MongoDB

Next article: Create Collection in MongoDB

5 ★ | 1 Vote