'This method makes use of the aggregation framework to
produce distinct values for a given field.'

def _distinct(self, field, flt=None, sort=None, limit=None, skip=None):

    pipeline = []
    if flt:
        pipeline.append({'$match': flt})
    if sort:
        pipeline.append({'$sort': OrderedDict(sort)})
    if (skip is not None):
        pipeline += [{'$skip': skip}]
    if (limit is not None):
        pipeline += [{'$limit': limit}]
    for i in range(field.count('.'), (-1), (-1)):
        subfield = field.rsplit('.', i)[0]
        if (subfield in self.needunwind):
            pipeline += [{'$unwind': ('$' + subfield)}]
    pipeline.append({'$group': {'_id': ('$%s' % field)}})
    return pipeline
