MongoDB Drop Database
MongoDB provides the ability to drop databases to clean up databases that are no longer needed. The drop operation is irreversible, so please use with caution.
Drop Current Database
Basic Syntax
Example
Pre-Deletion Confirmation
View Current Database
View Collection List
Complete Confirmation Flow
Safe Deletion Process
Step 1: Backup Data
Step 2: Verify Backup
Step 3: Execute Deletion
Drop Specific Database (Non-Current)
MongoDB doesn't have a direct command to drop non-current databases; you need to switch first:
Drop Multiple Databases
Batch Deletion Example
Drop Protection Mechanisms
Prevent Accidental Production Database Deletion
1. Use Admin Permission Control
2. Script Protection
Pre-Deletion Checklist
Restore Deleted Database
Restore from Backup
Restore from Replica Set
If replica set is configured, can restore from secondary:
Common Questions
Q: Space not released after dropping database?
A: MongoDB doesn't immediately release disk space; use compact command:
Q: How to delete all user data but keep structure?
A: Drop all collections instead of dropping database:
Q: How long does the drop operation take?
A: Depends on data volume:
- Small database (<1GB): Almost instantaneous
- Large database (>100GB): May take several minutes
Command Line Deletion
Non-Interactive Deletion
Script Deletion
Summary
Important notes for dropping databases:
- Irreversible operation: Always backup before dropping
- Confirm current database: Use
dbcommand to confirm - Protect system databases: Don't drop admin, local, config
- Monitor disk space: May need to compact to release space after deletion
In the next chapter, we will learn about MongoDB Create Collection.