Skip to content

Use correct syntax to apply query hint to aggregations #4238

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

Closed
naushadamin opened this issue Nov 22, 2022 · 1 comment
Closed

Use correct syntax to apply query hint to aggregations #4238

naushadamin opened this issue Nov 22, 2022 · 1 comment
Assignees
Labels
type: enhancement A general enhancement

Comments

@naushadamin
Copy link

Hello,

I've added the following hint option to 'force' an index:

AggregationOptions options = AggregationOptions.builder().hint(new Document("some_index", 1)).build();
final Aggregation aggregation1 = newAggregation(matchOperation1, projectionOperation, unwindOperation, matchOperation2, groupOperation1).withOptions(options);

However, the query throws an exception during runtime:

com.mongodb.MongoCommandException: Command failed with error 2: 'Cannot find index.' on server invoicedb-non-prod-3.ccune5xof3zy.us-east-2.docdb.amazonaws.com:27017. The full response is {"ok": 0.0, "operationTime": {"$timestamp": {"t": 1669081886, "i": 1}}, "code": 2, "errmsg": "Cannot find index."} at com.mongodb.internal.connection.ProtocolHelper.getCommandFailureException(ProtocolHelper.java:198) at com.mongodb.internal.connection.InternalStreamConnection.receiveCommandMessageResponse(InternalStreamConnection.java:418)

I confirmed the index some_index is available on target database/collection and I can verify usage of hint with an explain plan. Can you help the correct instruction to set hint ?

@christophstrobl
Copy link
Member

Thanks for reporting. We'll update AggregationOptions to allow direct usage of a given index name.

@christophstrobl christophstrobl added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels Nov 30, 2022
mp911de added a commit that referenced this issue Jan 11, 2023
Introduce HintFunction to encapsulate how hints are applied and to remove code duplications.

See #4238
Original pull request: #4243
@mp911de mp911de changed the title correct syntax to apply hint to aggregate query Use correct syntax to apply query hint to aggregations Jan 11, 2023
@mp911de mp911de added this to the 4.1 M1 (2023.0.0) milestone Jan 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants