Drop database in mongoDB

You are here : Home / MongoDB Tutorial


Contents of page >


1) Create/Switch to database you want to drop >


Once you are connected to mongoDB


MongoDB shell version: 3.0.6
connecting to: test     (Now, you are CONNECTED)
> use mydb
switched to db mydb
>


Above we created new database (if not exists) in mongoDB named mydb


2) Now, See list of all databases in MongoDb, where you can see mydb as well >
> show dbs
admin   0.078GB
local   0.078GB
mydb    0.078GB
testdb  0.078GB
yourdb  0.078GB
>
You can see mydb which you have created.


3) Drop database from mongoDB server >
Use db.dropDatabase() method to drop current database.
> db.dropDatabase()
{ "dropped" : "mydb", "ok" : 1 }


4) Now, again see list of all databases in MongoDb>
> show dbs
admin   0.078GB
local   0.078GB
testdb  0.078GB
yourdb  0.078GB
>
You can see mydb is dropped.


SUMMARY>
So in this mongoDB tutorial we used db.dropDatabase() method to drop current database in MongoDB.

Having any doubt? or you liked the tutorial! Please comment in below section.
Please express your love by liking JavaMadeSoEasy.com (JMSE) on facebook, following on google+ or Twitter.


RELATED LINKS>

What is MongoDB - A quick introduction to database



Create new database in mongoDB

Install and connect to MongoDB on windows


Labels: MongoDB
eEdit
Must read for you :