Q15: What is the difference between a Single-Field Index and a Compound Index?

  • Single-Field Index: Index constructed on a single key { email: 1 }.
  • Compound Index: Index constructed on multiple keys { status: 1, createdAt: -1 }. The order of fields matters significantly; queries must follow the Equality, Sort, Range (ESR) rule and match index prefix sequences.
Key Takeaways
  • Compound indexes support queries on prefix subsets of fields.
  • Follow the ESR Rule: Equality fields first, Sort fields second, Range fields last.
Knowledge Check

Given a compound index { a: 1, b: 1, c: 1 }, which query CANNOT utilize this index efficiently?