Skip to main content

How does MongoDB choose an execution plan when multiple indexes exist?

Senior MongoDB
Quick Answer MongoDB uses the query planner to select the best index. When multiple indexes could satisfy a query, the planner runs a "tournament" - it executes candidate plans in parallel for a trial period and picks the winner (fewest works to return the first batch of results). The winner is cached in the plan cache. Provide hints (db.collection.find().hint()) to force a specific index.

Answer

MongoDB tests candidate plans during a trial phase and caches the best plan to avoid repeated plan selection.
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