Drop database
dropDatabase removes the current database and every collection inside it.
In this page:
Syntax
use database_name
db.dropDatabase()
Drop database
db.dropDatabase() deletes the database you are currently using, including all collections, indexes and data. It is meant for tests and resets. Double check with db.getName() first, and never run it on production without a verified backup.
Note:
Run db.getName() to confirm which database you are on.
Example: Drop database
test> use scratch
switched to db scratch
scratch> db.getName()
scratch
scratch> db.dropDatabase()
{ ok: 1, dropped: 'scratch' }
⚠️ Run this in your own terminal or Node.js environment.
Related Topics
Common Mistakes
- Running it on the wrong database
- Having no backup
- Doing it on production from a habit
Chapter Summary
- dropDatabase deletes everything in the current database
- Check db.getName() first
- Irreversible without backups
- Ideal for test resets
🔒
Chapter Quiz — Complete all 6 topics to unlock
0/6 topics done
Complete these topics first: