def cleanup_extra_indexes(model_class):
    """
    Finds any extra indexes and removes those from mongodb.
    """
    extra_indexes = model_class.compare_indexes().get("extra", None)
    if not extra_indexes:
        return 0

    # mongoengine does not have the necessary method so we need to drop to
    # pymongo interfaces via some private methods.
    removed_count = 0
    c = model_class._get_collection()
    for extra_index in extra_indexes:
        try:
            c.drop_index(extra_index)
            LOG.debug(
                "Dropped index %s for model %s.", extra_index, model_class.__name__
            )
            removed_count += 1
        except OperationFailure:
            LOG.warning(
                "Attempt to cleanup index %s failed.", extra_index, exc_info=True
            )

    return removed_count

    Finds any extra indexes and removes those from mongodb.
    
st2common/st2common/models/db/__init__.py