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)
| 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. |
no outgoing calls