'Get a list of distinct values for `key` among all documents
in this collection.
Raises :class:`TypeError` if `key` is not an instance of
:class:`basestring` (:class:`str` in python 3).
All optional distinct parameters should be passed as keyword arguments
to this method. Valid options include:
- `maxTimeMS` (int): The maximum amount of time to allow the count
command to run, in milliseconds.
- `collation` (optional): An instance of
:class:`~pymongo.collation.Collation`. This option is only supported
on MongoDB 3.4 and above.
The :meth:`distinct` method obeys the :attr:`read_preference` of
this :class:`Collection`.
:Parameters:
- `key`: name of the field for which we want to get the distinct
values
- `filter` (optional): A query document that specifies the documents
from which to retrieve the distinct values.
- `**kwargs` (optional): See list of options above.
.. versionchanged:: 3.4
Support the `collation` option.'

def distinct(self, key, filter=None, **kwargs):

    if (not isinstance(key, string_type)):
        raise TypeError(('key    must    be    an    instance    of    %s' % (string_type.__name__,)))
    cmd = SON([('distinct', self.__name), ('key', key)])
    if (filter is not None):
        if ('query' in kwargs):
            raise ConfigurationError("can't    pass    both    filter    and    query")
        kwargs['query'] = filter
    collation = validate_collation_or_none(kwargs.pop('collation', None))
    cmd.update(kwargs)
    with self._socket_for_reads() as (sock_info, slave_ok):
        return self._command(sock_info, cmd, slave_ok, read_concern=self.read_concern, collation=collation)['values']
