Drop Database in MongoDB


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

EXAMPLE:
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
>db.dropDatabase()
>{ "dropped" : " myMongodb ", "ok" : 1 }

Now checklist 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 the default 'test' database

No comments:

Post a Comment

Please do not enter any spam link in the comment box.

Related Posts

Fatal Error: Peer authentication failed for user "postgres", when trying to get pgsql working with rails.

Problem: Sometimes, we get the following error when trying to make a connection in Rails.  FATAL ERROR: Peer authentication failed for us...