
- MongoDB Tutorial
- MongoDB - Home
- MongoDB - Overview
- MongoDB - Advantages
- MongoDB - Environment
- MongoDB - Data Modeling
- MongoDB - Create Database
- MongoDB - Drop Database
- MongoDB - Create Collection
- MongoDB - Drop Collection
- MongoDB - Data Types
- MongoDB - Insert Document
- MongoDB - Query Document
- MongoDB - Update Document
- MongoDB - Delete Document
- MongoDB - Projection
- MongoDB - Limiting Records
- MongoDB - Sorting Records
- MongoDB - Indexing
- MongoDB - Aggregation
- MongoDB - Replication
- MongoDB - Sharding
- MongoDB - Create Backup
- MongoDB - Deployment
- MongoDB - Java
- MongoDB - PHP
- Advanced MongoDB
- MongoDB - Relationships
- MongoDB - Database References
- MongoDB - Covered Queries
- MongoDB - Analyzing Queries
- MongoDB - Atomic Operations
- MongoDB - Advanced Indexing
- MongoDB - Indexing Limitations
- MongoDB - ObjectId
- MongoDB - Map Reduce
- MongoDB - Text Search
- MongoDB - Regular Expression
- Working with Rockmongo
- MongoDB - GridFS
- MongoDB - Capped Collections
- Auto-Increment Sequence
- MongoDB Useful Resources
- MongoDB - Questions and Answers
- MongoDB - Quick Guide
- MongoDB - Useful Resources
- MongoDB - Discussion
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.
- Related Articles
- Drop all indexes from all the collections in a MongoDB database using the command line?
- How do I know which MongoDB version is installed using the Command Line?
- How to drop a database in MongoDB?
- Connecting to MySQL database from the command line?
- Connect to MySQL database from command line
- How to drop a database in MongoDB using java?
- How do I Zip/Unzip on the Unix Command Line
- How can we analyze the tables of a particular database from MySQL Server command line?
- How can we drop a MySQL view from the database?
- How to create a database on command line in MySQL?
- How to drop a numeric collection from MongoDB?
- How can we get the list of tables in a particular database from MySQL Server command line?
- How to drop a table from a database using JDBC API?
- How do we print a variable at the MongoDB command prompt?
- How do I remove a MySQL database?

Advertisements