Skip to main content
InterviewHubPRO
Section Overview
Q29

Question 29 of 50

Part 3: Advanced Internals, Scale & Production Patterns (Senior / Lead)

58%
MongoDB & NoSQL (50 Qs)•Part 3: Advanced Internals, Scale & Production Patterns (Senior / Lead)

What is a Partial Index vs a Sparse Index in MongoDB?

senior LevelMost AskedCode ExampleDatabases & SQL

In Simple Words:

  • Sparse Index: Only indexes documents that contain the indexed field (skips documents where the field does not exist).
  • Partial Index (Modern Replacement): Indexes only documents that satisfy an explicit filter expression:
    javascript
    db.orders.createIndex(
      { orderId: 1 },
      { partialFilterExpression: { status: "ACTIVE" } }
    );
    
    Saves massive disk and RAM capacity by excluding millions of archived/cancelled orders from the index!