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

Method hint

pymongo/synchronous/cursor.py:768–790  ·  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

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

Callers 8

test_hintMethod · 0.45
test_hint_by_nameMethod · 0.45
findMethod · 0.45
test_cloneMethod · 0.45
test_hintMethod · 0.45
test_hint_by_nameMethod · 0.45
findMethod · 0.45
test_cloneMethod · 0.45

Calls 2

_check_okay_to_chainMethod · 0.95
_set_hintMethod · 0.95

Tested by 8

test_hintMethod · 0.36
test_hint_by_nameMethod · 0.36
findMethod · 0.36
test_cloneMethod · 0.36
test_hintMethod · 0.36
test_hint_by_nameMethod · 0.36
findMethod · 0.36
test_cloneMethod · 0.36