Skip to Main Content

MongoByte MongoDB Logo

Welcome to the new MongoDB Feedback Portal!

{Improvement: "Your idea"}
We’ve upgraded our system to better capture and act on your feedback.
Your feedback is meaningful and helps us build better products.

Status Will Not Implement
Created by Paul Coch
Created on Feb 26, 2026

Add Attribute Sorting/Reorganizing to get best index for $match in aggregation and other filters (by option)

What problem are you trying to solve?

Focus on the what and why of the need you have, not the how you'd like it solved.

I have found out that the order of attributes in my (different) $match stages are relevant to the query planner of what index to choose.

What would you like to see happen?

Describe the desired outcome or enhancement.

Since there was only a lot of filter conditions and one sorter, there would have been a correct index to use.I would love to see an option (per execution or even global where the query planner can reorganize the order of attributes from one (or if safe) more $matches or filter and check if there is one better fitting index (with more entries than only the first one)

Why is this important to you or your team?

Explain how the request adds value or solves a business need.

since we can not always control everything in our aggregations and queries due to user dynamic input, this could ensure us a lot of efficiency and speed.

What steps, if any, are you taking today to manage this problemTracing, reorganizing

tracing and reorganising queries and indexes


  • Admin
    Chris Harris
    Apr 21, 2026

    Hi @Guest, thanks for submitting this request. Broadly speaking what you describe is something that the optimizer has done for a while, for example see the $match + $match Coalescence and $sort + $match Sequence Optimization sections of the Aggregation Pipeline Optimization page. I'll therefore do two things. Firstly I'll close this request since, as written, it already seems to be implemented. Secondly I'll reach out to get more details about the specifics of the situation you encountered to better understand what's happening in your situation and to make sure that we have work planned to address it if needed.

    Best,
    Chris