MongoDB - Drop Database

MongoDB - Drop Database : In this chapter how to drop a database using MongoDB command.

The dropDatabase() Method

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


There are following 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 default 'test' database.


First, check the list of available databases by using the command, show dbs.
>show dbs
local      0.78125GB
mydb       0.23012GB
test       0.23012GB

If you want to delete new database <mydb>, then dropDatabase() command would be as follows −

>use mydb
switched to db mydb
>{ "dropped" : "mydb", "ok" : 1 }
Now check list of databases.
>show dbs
local      0.78125GB
test       0.23012GB

Welookups is optimized for learning.Copy right 2018 kumar aditya singh .
All Right Reserved and you agree to have read and accepted our term and condition.
All Rights Reserved.