Index की रणनीतियाँ
अच्छी indexing का मतलब है indexes को अपनी real queries से match करना, इन्हें कम रखना, और यह check करना कि ये इस्तेमाल होते हैं।
In this page:
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
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. #}
आम गलतियां
- real queries check किए बिना index करना
- unused indexes रखना
- 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: