0

The idea here would be to group these values into periods of 15 minutes. But i'm not even completely sure where to start with the aggregators, in fact, since this are all a single MongoDb entity i'm not even sure if aggregators are the best way to go at this.

All the data needed for a single day is within the "value" key.

{
  "_id": {
    "$oid": "63a1d8cfcf1a43844d68ca0a"
  },
  "date": "2022-01-01",
  "values": [
    {
      "timestamp": "2022-01-01T00:00:00",
      "meterValue": "6",
      "locationID": "LIS-00001"
    },
    {
      "timestamp": "2022-01-01T00:05:00",
      "meterValue": "20",
      "locationID": "LIS-00001"
    },
    {
      "timestamp": "2022-01-01T00:10:00",
      "meterValue": "13",
      "locationID": "LIS-00001"
    },
    {
      "timestamp": "2022-01-01T00:15:00",
      "meterValue": "4",
      "locationID": "LIS-00001"
    },
    {
      "timestamp": "2022-01-01T00:20:00",
      "meterValue": "11",
      "locationID": "LIS-00001"
    },
    {
      "timestamp": "2022-01-01T00:25:00",
      "meterValue": "5",
      "locationID": "LIS-00001"
    },
    {
      "timestamp": "2022-01-01T00:30:00",
      "meterValue": "3",
      "locationID": "LIS-00001"
    },
    {
      "timestamp": "2022-01-01T00:35:00",
      "meterValue": "16",
      "locationID": "LIS-00001"
    },
    {
      "timestamp": "2022-01-01T00:40:00",
      "meterValue": "1",
      "locationID": "LIS-00001"
    },
    {
      "timestamp": "2022-01-01T00:45:00",
      "meterValue": "0",
      "locationID": "LIS-00001"
    },...
  ]
}

This would output something like:

{
  "date: "2022-01-01T00:15:00",
  "meterValueSum": 39
},
{
  "date": "2022-01-01T00:30:00",
  "meterValueSum": 20
},
{
  "date": "2022-01-01T00:45:00",
  "meterValueSum": 20
},...
BryceSoker
  • 624
  • 1
  • 11
  • 29
  • 1
    Does this answer your question? [Group result by 15 minutes time interval in MongoDb](https://stackoverflow.com/questions/26814427/group-result-by-15-minutes-time-interval-in-mongodb) – ray Dec 20 '22 at 16:48
  • Nope, in that case, he is aggregating several entities, not a single one, the use case also seems quite different. – BryceSoker Dec 20 '22 at 16:50
  • 1
    You need to set `{$unwind: "$values"}`, then you can use solution from https://stackoverflow.com/questions/26814427/group-result-by-15-minutes-time-interval-in-mongodb Otherwise you would need [$reduce](https://www.mongodb.com/docs/rapid/reference/operator/aggregation/reduce/) but this will become rather complex. – Wernfried Domscheit Dec 20 '22 at 16:53

0 Answers0