def adv_query(db_col, agg):
    """
    Purpose:
        Does an advanced query
    Args:
        db_col - Mongodb collection
        agg - how to aggerate search
    Returns:
        query results
    """

    # Query Avg
    agg_result = db_col.aggregate(
        [
            {
                "$group": {
                    "_id": {
                        "firstDayOfMonth": {
                            "$dateTrunc": {"date": "$timestamp", "unit": agg},
                        },
                    },
                    "avgTotalCalls": {"$avg": "$total_calls"},
                    "avgCriticalCalls": {"$avg": "$critical"},
                    "avgNonCriticalCalls": {"$avg": "$non_critical"},
                    "avgFireCalls": {"$avg": "$fire"},
                }
            },
            {"$sort": {"_id": 1}},
        ]
    )

    # logging.info(list(agg_result))

    return list(agg_result)