Drop database in MongoDB 2016-05-25 05:39
Use db.dropDatabase()
to delete the current selected database. If no database selected this command will delete the default database test
. Before deleting you need show all database. Delete a database command like following.
> show dbs
local 0.078GB
new_database 0.078GB
user_database 0.078GB
> use user_database
switched to db user_database
> db.dropDatabase()
{ "dropped" : "user_database", "ok" : 1 }
> db
user_database
As you can see after executing db.dropDatabase()
the database user_database
is still there. If you execute db.users.insert()
, the database user_database
will "come back". But, switch to other database before inserting data user_database
will disappear unless you create it again.