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

Indexes क्या हैं

एक index एक ordered lookup structure है जो MongoDB को पूरी collection scan किए बिना documents ढूंढने देता है।

Indexes क्या हैं

बिना एक index के एक query एक collection scan perform करती है, हर document पढ़ते हुए। एक index selected fields को documents को pointers वाले एक sorted B-tree में store करता है, इसलिए reads fast हो जाती हैं, extra storage और slower writes की कीमत पर।

हर collection में _id पर automatically एक unique index होता है।

Note: Indexes reads तेज़ करते हैं लेकिन writes धीमी करते हैं, इसलिए सिर्फ ज़रूरी वाले add करें।

उदाहरण: What are indexes

bash
test> db.users.getIndexes()
[ { v: 2, key: { _id: 1 }, name: '_id_' } ]
test> db.users.createIndex({ email: 1 })
email_1
test> db.users.getIndexes().map(i => i.name)
[ '_id_', '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. हर field index करना
  2. query fields कभी index न करना
  3. यह भूल जाना कि _id पहले से indexed है
चैप्टर सारांश
  • Indexes full collection scans avoid करते हैं
  • ये B-tree structures हैं
  • इनकी storage और write speed cost है
  • _id automatically indexed है
🔒

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.