Skip to content

Use correct syntax to apply query hint to aggregations #4238

Closed
@naushadamin

Description

@naushadamin

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 ?

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions