def get_keyword_hierarchy(db):
    """
    Get the keyword hierarchy from the MongoDB
    :param db: MongoDB connection
    :return: Keyword hierarchy dict
    """
    result = {}
    keywords = list(db["keywords_hierarchy"].find())
    result["keyword_to_id"] = {
        keyword["value"]: str(keyword["id"])
        for keyword in keywords
    }
    result["id_to_children"] = {
        str(keyword["id"]): {
            "child_ids": [str(k) for k in keyword.get("childIds", [])],
            "value": keyword["value"]
        }
        for keyword in keywords
    }
    return result