- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How do I drop a MongoDB database from the command line?
To drop a MongoDB database from the command line, use the following syntax:
mongo yourDatabaseName --eval "db.dropDatabase()"
To understand the above syntax, let us display all the database from MongoDB. The query is as follows −
> show dbs;
The following is the output −
StudentTracker 0.000GB admin 0.000GB config 0.000GB local 0.000GB sample 0.000GB test 0.003GB
Drop the database with the name ‘StudentTracker’. The query is as follows to drop a database from command line −
C:\Program Files\MongoDB\Server\4.0\bin>mongo StudentTracker --eval "db.dropDatabase()"
The following is the output −
MongoDB shell version v4.0.5 connecting to: mongodb://127.0.0.1:27017/StudentTracker?gssapiServiceName=mongodb Implicit session: session { "id" : UUID("afc34e93-b4c0-46f0-85bd-b80ed17b8c11") } MongoDB server version: 4.0.5 { "dropped" : "StudentTracker", "ok" : 1 }
Now check the database has been dropped or not. The query is as follows −
> show dbs
The following is the output −
admin 0.000GB config 0.000GB local 0.000GB sample 0.000GB test 0.003GB
Look at the sample output, the database ‘StudentTracker’ has been dropped.
Advertisements