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

Drop collection

drop removes an entire collection with all its documents and indexes.

In this page:

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

bash
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
  1. Using drop when you meant deleteMany
  2. Losing index definitions
  3. 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:

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.