Apr-11-2021, 06:29 PM
(This post was last modified: Apr-11-2021, 06:43 PM by Larz60+.
Edit Reason: fixed bbcode tags, indentation
)
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"} } } )