MCPcopy Index your code
hub / github.com/mongodb/mongo-python-driver / hint

Method hint

pymongo/asynchronous/cursor.py:770–792  ·  view source on GitHub ↗

Adds a 'hint', telling Mongo the proper index to use for the query. Judicious use of hints can greatly improve query performance. When doing a query on multiple fields (at least one of which is indexed) pass the indexed field as a hint to the query. Raises :class:`~p

(self, index: Optional[_Hint])

Source from the content-addressed store, hash-verified

768 self._hint = helpers_shared._index_document(index)
769
770 def hint(self, index: Optional[_Hint]) -> AsyncCursor[_DocumentType]:
771 """Adds a 'hint', telling Mongo the proper index to use for the query.
772
773 Judicious use of hints can greatly improve query
774 performance. When doing a query on multiple fields (at least
775 one of which is indexed) pass the indexed field as a hint to
776 the query. Raises :class:`~pymongo.errors.OperationFailure` if the
777 provided hint requires an index that does not exist on this collection,
778 and raises :class:`~pymongo.errors.InvalidOperation` if this cursor has
779 already been used.
780
781 `index` should be an index as passed to
782 :meth:`~pymongo.asynchronous.collection.AsyncCollection.create_index`
783 (e.g. ``[('field', ASCENDING)]``) or the name of the index.
784 If `index` is ``None`` any existing hint for this query is
785 cleared. The last hint applied to this cursor takes precedence
786 over all others.
787
788 :param index: index to hint on (as an index specifier)
789 """
790 self._check_okay_to_chain()
791 self._set_hint(index)
792 return self
793
794 def comment(self, comment: Any) -> AsyncCursor[_DocumentType]:
795 """Adds a 'comment' to the cursor.

Callers

nothing calls this directly

Calls 2

_check_okay_to_chainMethod · 0.95
_set_hintMethod · 0.95

Tested by

no test coverage detected