To drop existing database we can use dropDatabase() function. It's also dropping all the related data files.
Syntax
Basic syntax of drop database is as follow
db.dropDatabase()
|
To drop database you have to follow the given step carefully because if wrong by mistake you delete the wrong database it may create a problem in data backup.
1-First you check which database you want to delete exists or not. To check existing of the database you can you the following command.
show dbs
Result
Test 0.078GB
admin (empty)
local 0.078GB
myMongoDB 0.078GB
|
2-Switch to existing database use the following command, suppose I want to delete “myMongoDB” database.
>use myMongoDB
Result
switched to db myMongoDB
|
3- Now run the following command to drop “myMongoDB” database.
db.dropDatabase()
Result
/* 1 */
{
"dropped" : " myMongoDB ",
"ok" : 1.0
}
|
4- Now check the list of database.
show dbs
Result
Test 0.078GB
admin (empty)
local 0.078GB
|
Now you can see myMongoDB is not exists in the list.