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

Index की रणनीतियाँ

अच्छी indexing का मतलब है indexes को अपनी real queries से match करना, इन्हें कम रखना, और यह check करना कि ये इस्तेमाल होते हैं।

In this page:

  1. Index Strategies

Index Strategies

अपनी सबसे slow, सबसे frequent queries से शुरू करें, ESR rule से compound indexes design करें, और $indexStats से मिले unused indexes remove करें।

Covered queries पूरी तरह index से answer देती हैं। हर extra index write cost और memory pressure add करता है, इसलिए दोनों balance करें।

Profiler से monitor करें।

Note: $indexStats दिखाता है कौन-से indexes actually इस्तेमाल हो रहे हैं।

उदाहरण: Index strategies

bash
test> db.orders.aggregate([{ $indexStats: {} }, { $project: { name: 1, "accesses.ops": 1 } }])
[
  { name: '_id_', accesses: { ops: Long('1204') } },
  { name: 'status_1_createdAt_-1', accesses: { ops: Long('9821') } },
  { name: 'legacy_flag_1', accesses: { ops: Long('0') } }
]
test> db.orders.dropIndex("legacy_flag_1")
{ nIndexesWas: 3, ok: 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. real queries check किए बिना index करना
  2. unused indexes रखना
  3. indexes के लिए memory limits ignore करना
चैप्टर सारांश
  • Real query patterns के लिए index करें
  • Compound indexes के लिए ESR इस्तेमाल करें
  • Unused indexes drop करें
  • Covered queries सिर्फ index पढ़ती हैं
🔒

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.