InterviewHubPRO
Section Overview
Q30

Question 30 of 60

Part 3: NoSQL & Document Databases (MongoDB, DynamoDB) (26 - 40)

50%
Databases & System Design•Part 3: NoSQL & Document Databases (MongoDB, DynamoDB) (26 - 40)

MongoDB Compound & Multikey Indexes:

In Simple Words:

  • Compound Index: Indexes multiple fields; follows leftmost prefix rule.
  • Multikey Index: Indexes an array field by creating an index entry for every element in the array.
javascript
// Compound index on status and createdAt:
db.orders.createIndex({ status: 1, createdAt: -1 });

// Multikey index on array field 'tags':
db.articles.createIndex({ tags: 1 });
db.articles.find({ tags: "tech" }); // Fast indexed array search!