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

Collection Drop करना

drop एक पूरी collection इसके सारे documents और indexes समेत remove करता है।

In this page:

  1. Drop Collection
Syntax
javascript
db.collection_name.drop()

Drop Collection

db.collection.drop() collection delete करता है और अगर यह exist करती थी तो true return करता है। एक-एक करके documents delete करने से यह कहीं ज़्यादा तेज़ है लेकिन indexes और validation rules भी remove कर देता है। इसे temporary या staging collections के लिए इस्तेमाल करें।

Note: अगर collection exist न करे तो drop false return करता है।

उदाहरण: 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/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. deleteMany मतलब होने पर drop इस्तेमाल करना
  2. index definitions खोना
  3. गलत database में drop करना
चैप्टर सारांश
  • drop collection और इसके indexes remove करता है
  • true या false return करता है
  • सारे documents delete करने से तेज़
  • Undo नहीं हो सकता
🔒

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.