explain() का उपयोग
explain दिखाता है कि MongoDB एक query कैसे execute करता है: इसने कौन-सा index इस्तेमाल किया और कितने documents examine किए।
In this page:
Syntax
db.collection_name.find(filter).explain("executionStats")
explain()
एक cursor पर .explain("executionStats") call करें। IXSCAN (index scan) बनाम COLLSCAN (full scan) के लिए winningPlan देखें, और totalDocsExamined को nReturned से compare करें।
एक बड़ा gap मतलब query inefficient है। hint() testing के लिए एक particular index force करता है।
Note:
totalDocsExamined को nReturned के करीब रखने का लक्ष्य रखें।
उदाहरण: explain()
test> db.users.find({ email: "[email protected]" }).explain("executionStats").executionStats
{
nReturned: 1,
totalKeysExamined: 1,
totalDocsExamined: 1,
executionStages: { stage: 'FETCH', inputStage: { stage: 'IXSCAN', indexName: 'email_1' } }
}
⚠️ 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. #}
आम गलतियां
- plans में COLLSCAN ignore करना
- छोटे data पर timing trust करना
- docs examined को returned से compare न करना
चैप्टर सारांश
- explain query plan दिखाता है
- IXSCAN एक index इस्तेमाल करता है, COLLSCAN नहीं
- docs examined और returned compare करें
- hint एक index force करता है
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: