Drop collection
drop removes an entire collection with all its documents and indexes.
In this page:
Syntax
db.collection_name.drop()
Drop collection
db.collection.drop() deletes the collection and returns true if it existed. It is much faster than deleting documents one by one but removes indexes and validation rules too. Use it for temporary or staging collections.
Note:
drop returns false if the collection does not exist.
Example: Drop collection
test> db.temp.insertMany([{ _id: 1 }, { _id: 2 }])
{ acknowledged: true, insertedIds: { '0': 1, '1': 2 } }
test> db.temp.countDocuments()
2
test> db.temp.drop()
true
test> db.temp.countDocuments()
0
⚠️ Run this in your own terminal or Node.js environment.
Related Topics
Common Mistakes
- Using drop when you meant deleteMany
- Losing index definitions
- Dropping in the wrong database
Chapter Summary
- drop removes the collection and its indexes
- Returns true or false
- Faster than deleting all documents
- Cannot be undone
🔒
Chapter Quiz — Complete all 6 topics to unlock
0/6 topics done
Complete these topics first: