Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Aggregate
#1
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"}
        }
    }
)
Reply
#2
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python group by and aggregate dervast 1 869 Aug-27-2019, 12:12 PM
Last Post: ThomasL
  How to aggregate rows with same column Leoni 1 1,408 Jul-08-2018, 08:33 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020