How to delete or drop MongoDB database
How to delete or drop MongoDB database
In this MongoDB Tutorial, we shall learn to drop or delete a MongoDB Database.
To delete or drop a database from MongoDB, follow the below steps :
1. Select the database you want to delete with following "USE <database>" command.
Following is the syntax of USE command : use <database_name>
2. Drop the database with following "db.dropDatabase()" command.
Following is the syntax of dropDatabase command : db.dropDatabase()
Check all the Databases:
> show dbs;
admin 0.000GB
config 0.000GB
dev_xxxxx 0.000GB
local 0.000GB
prod_xxxxx 0.000GB
testing 0.000GB
admin 0.000GB
config 0.000GB
dev_xxxxx 0.000GB
local 0.000GB
prod_xxxxx 0.000GB
testing 0.000GB
Select the DB you want to Delete:
> use prod_xxxxx;
switched to db prod_xxxxx
> db.dropDatabase()
{ "dropped" : "prod_xxxxx", "ok" : 1 }
> show dbs;
admin 0.000GB
config 0.000GB
dev_xxxxx 0.000GB
local 0.000GB
testing 0.000GB
Useful MongoDB Articles:
- How To Install MongoDB 4 on RHEL 8 / CentOS 8
- How To Install MongoDB 4 on RHEL 7 / CentOS 7
- How to Create MongoDB database and Collections
- MongoDB: Install Mongo Client and Mongo Shell in Ubuntu, CentOS
- How to delete or drop MongoDB database
- MongoDB Startup Error
- MongoDB 3.x Installation and Initial Configuration
No comments