How to add index hint option to aggregate query in PyMongo

Viewed 377

Using PyMongo, is there a way to add an index hint to an aggregate query?

None of these option works with PyMongo:

db.collection.aggregate(pipeline, {'hint': 'index_name'}) db.collection.aggregate(pipeline).hint(index_name')

1 Answers

I don't believe this is supported.

Separately, hint specifies an index to use for the particular query; an aggregation pipeline can contain many queries. Simply specifying index name would be ambiguous.

Related