Skip to content

MONGOID-5887 Update mongo.rb to add hint in the aggregates #6019

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

akshay58538
Copy link

@akshay58538 akshay58538 commented Jul 23, 2025

MongoID aggregates dont propagate the hint passed in the criteria, into the pipeline aggregate.

This causes the query to ignore the hint and use an index decided by the planner, which is not ideal for the cases where the user intentionally passed a certain hint.

@akshay58538 akshay58538 requested a review from a team as a code owner July 23, 2025 18:55
@akshay58538 akshay58538 requested a review from jamis July 23, 2025 18:55
@jamis jamis changed the title Update mongo.rb to add hint in the aggregates MONGOID-5887 Update mongo.rb to add hint in the aggregates Jul 28, 2025
Copy link
Contributor

@jamis jamis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, this is a great catch. We should definitely be appending the hint to that request.

Could you add a test or two, to make sure we don't regress at some point in the future? If you aren't sure how to add a test for something like this, you can look at https://github.com/mongodb/mongoid/blob/master/spec/integration/criteria/alias_query_spec.rb#L53-L97 for an example of using event subscribers in specs to inspect the commands as they are sent to the database. I'm happy to answer any questions as well, if that would help.

Thank you!

@johnnyshields
Copy link
Contributor

Oh wow. I had seen this behavior but naively assumed hints weren't supported by the aggregation pipeline 🤦‍♂️ Truly great catch!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants