Skip to main content

How does MongoDB optimize read patterns using index intersection?

Expert MongoDB
Quick Answer MongoDB can combine results from two separate indexes using index intersection (AND_HASH/AND_SORTED plan stages). The planner may choose this over a single compound index if it estimates fewer total keys examined. In practice, a well-designed compound index usually outperforms intersection due to lower overhead. Use explain() to verify - if intersection is being used consider adding a compound index instead.

Answer

MongoDB combines multiple indexes to satisfy a query when no compound index exists. This improves performance compared to full scans but is slower than a single optimal compound index.
S
SugharaIQ Editorial Team Verified Answer

This answer has been peer-reviewed by industry experts holding senior engineering roles to ensure technical accuracy and relevance for modern interview standards.

Want to bookmark, take notes, or join discussions?

Sign in to access all features and personalize your learning experience.

Sign In Create Account

Source: SugharaIQ

Ready to level up? Start Practice