'Compares the indexes defined in MongoEngine with the ones
existing in the database. Returns any missing/extra indexes.'

@classmethod
def compare_indexes(cls):

    required = cls.list_indexes()
    existing = [info['key'] for info in cls._get_collection().index_information().values()]
    missing = [index for index in required if (index not in existing)]
    extra = [index for index in existing if (index not in required)]
    if ([(u'_cls', 1)] in missing):
        cls_obsolete = False
        for index in existing:
            if (includes_cls(index) and (index not in extra)):
                cls_obsolete = True
                break
        if cls_obsolete:
            missing.remove([(u'_cls', 1)])
    return {'missing': missing, 'extra': extra}
