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

Index के प्रकार

ordinary indexes के अलावा MongoDB multikey, text, geospatial, hashed, TTL, partial, और wildcard indexes offer करता है।

In this page:

  1. Index Types
Syntax
javascript
db.collection_name.createIndex({ array_field: 1 })            // multikey
db.collection_name.createIndex({ location: "2dsphere" })     // geospatial

Index Types

एक array field index करना प्रति element एक entry वाला एक multikey index बनाता है। 2dsphere indexes geospatial queries support करते हैं, hashed indexes hashed sharding और equality support करते हैं, TTL indexes एक time के बाद documents delete करते हैं, और partial indexes सिर्फ एक filter match करने वाले documents cover करते हैं।

Wildcard indexes unpredictable field names cover करते हैं।

Note: जब आप सिर्फ एक subset query करें partial indexes छोटे और तेज़ होते हैं।

उदाहरण: Index types

bash
test> db.posts.createIndex({ tags: 1 })                          // multikey
test> db.places.createIndex({ location: "2dsphere" })            // geospatial
test> db.logs.createIndex({ at: 1 }, { expireAfterSeconds: 86400 }) // TTL: one day
test> db.users.createIndex({ email: 1 }, { partialFilterExpression: { active: true }, unique: true })
test> db.users.createIndex({ "$**": 1 })                         // wildcard

⚠️ 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. query के लिए गलत type इस्तेमाल करना
  2. यह भूल जाना कि TTL indexes लगभग एक मिनट में एक बार चलते हैं
  3. unbounded बढ़ने वाले arrays index करना
चैप्टर सारांश
  • Multikey array elements index करता है
  • Geo queries के लिए 2dsphere
  • TTL documents expire करता है
  • Partial indexes एक subset cover करते हैं
🔒

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.