Now for using index we can use helper cursor.hint(index). index should be an index as passed to create_index() (e.g. [('field', ASCENDING)]):
collection.ensure_index(name="indexname", [("length", pymongo.ASCENDING)]) cursor.hint([("length", pymongo.ASCENDING)])
But it will be more flexible to get an opportunity to write
collection.ensure_index(name="indexname", [("length", pymongo.ASCENDING)]) cursor.hint("indexname")
- is depended on by
-
PYTHON-744 Allow count to work with query hints
- Closed