In this chapter, we are able to see the way to drop a database the use of MongoDB command.
The dropDatabase() Method
MongoDB db.DropDatabase() command is used to drop a current database.
Syntax
Basic syntax of dropDatabase() command is as follows −
db.dropDatabase()
This will delete the selected database. If you have not decided on any database, then it's going to delete default 'test' database.
Example
First, test the list of available databases by means of the usage of the command, display dbs.
>show dbs
local 0.78125GB
mydb 0.23012GB
test 0.23012GB
>
If you want to delete new database <mydb>, then dropDatabase() command might be as follows −
>use mydb
switched to db mydb
>db.dropDatabase()
>{ "dropped" : "mydb", "ok" : 1 }
>
Now check listing of databases.
>show dbs
local 0.78125GB
test 0.23012GB
>