← Back to MongoDB Course | Chapter 8: Indexes | Lesson 6 of 7

explain() का उपयोग

explain दिखाता है कि MongoDB एक query कैसे execute करता है: इसने कौन-सा index इस्तेमाल किया और कितने documents examine किए।

In this page:

  1. explain()
Syntax
javascript
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()

bash
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. #}
आम गलतियां
  1. plans में COLLSCAN ignore करना
  2. छोटे data पर timing trust करना
  3. 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:

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.