'Find unique indexes in the document schema and return them.'

@classmethod
def _unique_with_indexes(cls, namespace=''):

    unique_indexes = []
    for (field_name, field) in cls._fields.items():
        sparse = field.sparse
        if field.unique:
            unique_fields = [field.db_field]
            if field.unique_with:
                if isinstance(field.unique_with, six.string_types):
                    field.unique_with = [field.unique_with]
                unique_with = []
                for other_name in field.unique_with:
                    parts = other_name.split('.')
                    parts = cls._lookup_field(parts)
                    name_parts = [part.db_field for part in parts]
                    unique_with.append('.'.join(name_parts))
                    parts[(-1)].required = True
                    sparse = ((not sparse) and (parts[(-1)].name not in cls.__dict__))
                unique_fields += unique_with
            fields = [(('%s%s' % (namespace, f)), pymongo.ASCENDING) for f in unique_fields]
            index = {'fields': fields, 'unique': True, 'sparse': sparse}
            unique_indexes.append(index)
        if (field.__class__.__name__ == 'ListField'):
            field = field.field
        if ((field.__class__.__name__ == 'EmbeddedDocumentField') and (field.document_type != cls)):
            field_namespace = ('%s.' % field_name)
            doc_cls = field.document_type
            unique_indexes += doc_cls._unique_with_indexes(field_namespace)
    return unique_indexes
