Python Forum

Full Version: Aggregate
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have a document with id, timestamp and a value field. How can I use aggregate function to get avg, min and max grouped by id and everyday? Here’s the snippet I am using. The snippet has a flaw that it use timestamp and not the date part from the timestamp. Any help would be appcreciated much.

document = db_collection.aggregate(
    {
        "$group": {
            "_id": {"$device_id"},
            "timestamp": {"$timestamp"},
            "average": {"$avg": "$value"},
            "minimum": {"$min": "$value"},
            "maximum": {"$max": "$value"}
        }
    }
)
This question is a bit vague in details of what aggregate is or where it comes from.
what is db_collection? its definition is not shown or the module it comes from is not stated.
Please see the How to ask Smart Questions link in my singnature