drop() (Drop a Collection)
Last updated: 2026-10-09
drop() (Drop a Collection)
drop() removes an entire collection — all documents, indexes, and metadata, e.g. `db.users.drop()`. Unlike deleteMany(), which only deletes documents, drop() also discards indexes and collection settings, requiring a full rebuild afterward. The operation cannot be undone and is among the most destructive commands — verify the collection name and scope before running.
| Category | Index & Admin |
|---|---|
| MongoDB Version | 1.0+ |
| Example Language | mongosh (Shell) |
📝 Syntax
db.<collection>.drop()
Returns:true on success; false when the collection does not exist.
▶ Example
Run the commands below in your local mongosh (requires a running mongod):
// drop: remove the temp_data collection
const ok = db.temp_data.drop()
print('Dropped: ' + ok)
Output:
Dropped: true
📌 Notes
- Indexes and metadata go too — expect a full rebuild
- Irreversible; double-check the name first
- Recovery relies on backups and loses all writes since the backup
🏷️ Related Tags
💡 Related Cases
📚 Related Tutorials
❓ FAQ
QWhat is the difference between drop and deleteMany?
AdeleteMany() removes matching documents only, keeping the collection, indexes, and settings; drop() deletes the whole collection including indexes and metadata.
QCan a dropped collection be recovered?
ANot via the API. Only a backup can restore it, losing all writes made after the backup.
QWhat does drop return for a nonexistent collection?
AIt returns false without throwing — useful as an existence check.