How to delete everything in a MongoDB database?

You can delete everything in a MongoDB database using the dropDatabase() method. This operation permanently removes the entire database and all its collections.

Syntax

use databaseName;
db.dropDatabase();

Example: Delete Entire Database

Let's first display all existing databases ?

show dbs
admin           0.000GB
config          0.000GB
flightInformation 0.000GB
local           0.000GB
sample          0.000GB
sampleDemo      0.000GB
test            0.003GB

Now we'll delete everything from the flightInformation database. First, switch to that database ?

use flightInformation
switched to db flightInformation

Execute the drop operation ?

db.dropDatabase()
{ "dropped" : "flightInformation", "ok" : 1 }

Verify Database Deletion

List databases again to confirm the deletion ?

show dbs
admin           0.000GB
config          0.000GB
local           0.000GB
sample          0.000GB
sampleDemo      0.000GB
test            0.003GB

The flightInformation database has been completely removed.

Key Points

  • dropDatabase() is irreversible ? all data, collections, and indexes are permanently deleted.
  • You must use the target database before calling dropDatabase().
  • The operation returns a confirmation with the dropped database name.

Conclusion

Use db.dropDatabase() to completely remove a MongoDB database and all its contents. Always ensure you're in the correct database context before executing this destructive operation.

Updated on: 2026-03-15T00:08:01+05:30

610 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements