'Lists all of the indexes that should be created for given
collection. It includes all the indexes from super- and sub-classes.'

@classmethod
def list_indexes(cls):

    if cls._meta.get('abstract'):
        return []
    classes = []
    def get_classes(cls):
        if ((cls not in classes) and isinstance(cls, TopLevelDocumentMetaclass)):
            classes.append(cls)
        for base_cls in cls.__bases__:
            if (isinstance(base_cls, TopLevelDocumentMetaclass) and (base_cls != Document) and (not base_cls._meta.get('abstract')) and (base_cls._get_collection().full_name == cls._get_collection().full_name) and (base_cls not in classes)):
                classes.append(base_cls)
                get_classes(base_cls)
        for subclass in cls.__subclasses__():
            if (isinstance(base_cls, TopLevelDocumentMetaclass) and (subclass._get_collection().full_name == cls._get_collection().full_name) and (subclass not in classes)):
                classes.append(subclass)
                get_classes(subclass)
    get_classes(cls)
    def get_indexes_spec(cls):
        indexes = []
        if cls._meta['index_specs']:
            index_spec = cls._meta['index_specs']
            for spec in index_spec:
                spec = spec.copy()
                fields = spec.pop('fields')
                indexes.append(fields)
        return indexes
    indexes = []
    for klass in classes:
        for index in get_indexes_spec(klass):
            if (index not in indexes):
                indexes.append(index)
    if ([(u'_id', 1)] not in indexes):
        indexes.append([(u'_id', 1)])
    if (cls._meta.get('index_cls', True) and cls._meta.get('allow_inheritance')):
        indexes.append([(u'_cls', 1)])
    return indexes
