Collection Drop करना
drop एक पूरी collection इसके सारे documents और indexes समेत remove करता है।
In this page:
Syntax
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
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. #}
आम गलतियां
- deleteMany मतलब होने पर drop इस्तेमाल करना
- index definitions खोना
- गलत 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: