Contents
How to drop database in MongoDB
In this guide, i will show you how drop a database in MongoDB.
The dropDatabase() Method
MongoDB db.dropDatabase() command is used to drop a existing database.
Syntax:
Basic syntax of dropDatabase() command is as follows:
db.dropDatabase()
This will delete the selected database.
NB: If you have not selected any database, the “test” default database will be deleted.
1. check the list available databases:
Issue “show dbs” to display all available databases.
1 2 3 4 5 6 7 8 9 |
[user@devops-team $] mongo MongoDB shell version: 2.0.4 connecting to: test > > > show dbs devops-teamDB 0.0625GB mydb 0.0625GB local (empty) |
2. Drop a database (devops-teamDB):
If you want to delete database <devops-teamDB>, then devops-teamDB() command would be as follows:
switched to db devops-teamDB
1 2 3 4 |
> > db.dropDatabase() { "dropped" : "devops-teamDB", "ok" : 1 } > |
Now check list of databases:
1 2 3 4 |
> > show dbs mydb 0.0625GB local (empty) |
3. Conclusion
In this post, i have explained How to drop database in MongoDB.
If you have any questions or feedback, feel free to leave a comment.
As always, if you found this post useful, then click like and share it 🙂