← Back to MongoDB Course | Chapter 5: CRUD — Delete | Lesson 5 of 6

Drop database

dropDatabase removes the current database and every collection inside it.

In this page:

  1. Drop database
Syntax
javascript
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

bash
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
  1. Running it on the wrong database
  2. Having no backup
  3. 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:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.