
- 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 to delete everything in a MongoDB database?
You can delete everything in a MongoDB database using dropDatabase() function. The syntax is as follows −
use yourDatabaseName; db.dropDatabase();
The above syntax will delete everything in a MongoDB database.
To delete everything in a MongoDB database, let us first display all the databases from MongoDB. The query is as follows −
> show dbs
The following is the output −
use yourDatabaseName; admin 0.000GB config 0.000GB flighInformation 0.000GB local 0.000GB sample 0.000GB sampleDemo 0.000GB test 0.003GB
Now we will delete everything from the database ‘flightInformation’.
First, you need to switch the database to ‘flightInformation’. The query is as follows −
> use flighInformation; switched to db flighInformation
Now here is the query to delete everything from database ‘flightInformation’ −
> db.dropDatabase();
The following is the output −
{ "dropped" : "flighInformation", "ok" : 1 }
Here is the query to list all databases −
> show dbs;
The following is the output −
admin 0.000GB config 0.000GB local 0.000GB sample 0.000GB sampleDemo 0.000GB test 0.003GB
Look at the sample output, everything has been deleted from the database ‘flightInformation’.
- Related Articles
- How to delete a table from MongoDB database?
- How to delete a document in MongoDB?
- How to drop a database in MongoDB?
- How to clear a MongoDB database?
- How to delete data in a MySQL database with Java?
- How to create a new database in MongoDB?
- How to delete documents from a collection in MongoDB?
- Everything is stored in database in SAP system
- How to delete multiple ids in MongoDB?
- How to delete partial data in MongoDB?
- How to delete a MongoDB document using Java?
- How to delete particular data in a document in MongoDB?
- How to drop a database in MongoDB using java?
- How to create a database in MongoDB using Java?
- Is it possible to delete everything after a 'space' in a MySQL field?

Advertisements