def clean_mongo_key(key):
    """mongodb dict keys cannot contain periods or start with a $"""
    key = key.replace(".", "_")
    if key.startswith("$"):
        key = key.replace("$", "_", 1)
    return key