Drop Database in MongoDB

The dropDatabase() Method
MongoDB db.dropDatabase() command is used to drop a existing database.
By using the command ‘show dbs’ check the available list of databases

>show dbs
local      0.78234GB
myMongodb       0.343012GB
test       0.43012GB

If you want to delete new database <myMongodb>, then use dropDatabase() command as below.

>use myMongodb
switched to db myMongodb
>{ "dropped" : " myMongodb ", "ok" : 1 }

Now check list of databases

>show dbs
local      0.78234GB
test       0. 43012GB

Note: This will delete the selected database. If you have not selected any database, then it will delete default 'test' database

No comments:

Post a Comment

PostgreSQL-Query: Sort result set by specific field values using ORDER BY Clause

Problem: Suppose we have a book_inventory table which has some columns such as id, isbn, title, author, publisher, publish_date, etc.. whe...