Dropping a Database — MongoDB Technical Interview Questions & Answers
Removing a database and all its collections.
Dropping a Database
- Simple meaning: Dropping a database removes all collections inside it.
- How to use: use college then db.dropDatabase(). Or drop one collection: db.students.drop().
- Backup first with mongodump if the data matters.
- Common mistake: drop on Atlas prod. Check db.getName().
- Interview tip: dropDatabase vs collection.drop — say the blast radius.
Technical Interview Tip: Say what is deleted: DB vs one collection.
Code Examples for Dropping a Database
Dropping a Database — working example
use prep_pilot
db.dropDatabase()Dropping a Database — db.dropDatabase() deletes the current database and all its collections.
How to Explain Dropping a Database to an Interviewer
How do you drop only students?
db.students.drop()