intermediateTop 30 Scenario-Based Questions
A MongoDB collection has a compound index on {status:1, createdAt:-1} but queries with only createdAt are slow. Why?
Leftmost prefix rule: a compound index on {status:1, createdAt:-1} supports: WHERE status = X (uses leftmost prefix). WHERE status = X AND createdAt = Y (uses both). But NOT: WHERE createdAt = Y (skips status — index not used). Fix: 1) Create a separate index on createdAt: db.orders.createIndex({createdAt:-1}). 2) Or if queries span both patterns, create two separate indexes. 3) Rule: equality con
This is a Pro chapter
Sign in, then upgrade to Pro or Power to unlock this and the full Databases Mastery library.
A MongoDB collection has a compound index on {status:1, createdAt:-1} but queries with only createdAt are slow. Why?