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

Method distinct

pymongo/synchronous/cursor.py:942–968  ·  view source on GitHub ↗

Get a list of distinct values for `key` among all documents in the result set of this query. Raises :class:`TypeError` if `key` is not an instance of :class:`str`. The :meth:`distinct` method obeys the :attr:`~pymongo.collection.Collection.read_preference` o

(self, key: str)

Source from the content-addressed store, hash-verified

940 return y
941
942 def distinct(self, key: str) -> list[Any]:
943 """Get a list of distinct values for `key` among all documents
944 in the result set of this query.
945
946 Raises :class:`TypeError` if `key` is not an instance of
947 :class:`str`.
948
949 The :meth:`distinct` method obeys the
950 :attr:`~pymongo.collection.Collection.read_preference` of the
951 :class:`~pymongo.collection.Collection` instance on which
952 :meth:`~pymongo.collection.Collection.find` was called.
953
954 :param key: name of key for which we want to get the distinct values
955
956 .. seealso:: :meth:`pymongo.collection.Collection.distinct`
957 """
958 options: dict[str, Any] = {}
959 if self._spec:
960 options["query"] = self._spec
961 if self._max_time_ms is not None:
962 options["maxTimeMS"] = self._max_time_ms
963 if self._comment:
964 options["comment"] = self._comment
965 if self._collation is not None:
966 options["collation"] = self._collation
967
968 return self._collection.distinct(key, session=self._session, **options)
969
970 def _send_message(self, operation: Union[_Query, _GetMore]) -> None:
971 """Send a query or getmore operation and handles the response.

Callers 15

listMethod · 0.45
listMethod · 0.45
test_distinctMethod · 0.45
test_no_removeMethod · 0.45
collection_distinctMethod · 0.45
cursor_distinctMethod · 0.45
test_cursorMethod · 0.45
test_readsMethod · 0.45
_test_auto_encryptMethod · 0.45

Calls

no outgoing calls

Tested by 15

test_distinctMethod · 0.36
test_no_removeMethod · 0.36
collection_distinctMethod · 0.36
cursor_distinctMethod · 0.36
test_cursorMethod · 0.36
test_readsMethod · 0.36
_test_auto_encryptMethod · 0.36
test_distinctMethod · 0.36
test_distinctMethod · 0.36