Q14: What are Indexes in MongoDB, and why are they crucial for performance?

Indexes are specialized B-Tree data structures that store a small portion of the collection dataset in an easily traversable order. Without indexes, MongoDB performs a Collection Scan (COLLSCAN), inspecting every document. With indexes, MongoDB performs an Index Scan (IXSCAN), retrieving matching documents instantly.

Key Takeaways
  • Reduces query time complexity from $O(N)$ to $O(log N)$.

  • Trade-off: Speeds up reads but adds memory overhead and slightly slows writes.

Knowledge Check

Which scan type occurs when a query executes without an applicable index?