I have the following document structure:
{
"_id": "5d2708ff79263ba40e54c08c",
"meta": {
"uid": "dd41ca10-a3c2-11e9-a1dd-fbec9d04cb25",
"firmware": "0.0.1",
"timestamp": "2019-07-11T10:01:35.264Z"
},
"sensors": [
{
"_id": "5d2708ff79263ba40e54c08e",
"name": "sensor1",
"value": 0.09050827850822706
},
{
"_id": "5d2708ff79263ba40e54c08d",
"name": "sensor2",
"value": 0.06592630654288716
}
]
}
What I'm trying to do is to select all documents per minute and then calculate every sensor's average value and get something like this:
{
"_id": "5d2708ff79263ba40e54c08c",
"meta": {
"uid": "dd41ca10-a3c2-11e9-a1dd-fbec9d04cb25",
"firmware": "0.0.1",
"timestamp": "2019-07-11T10:01:35.264Z"
},
"sensors": [
{
"_id": "5d2708ff79263ba40e54c08e",
"name": "sensor1",
"avg": 0.1111111
},
{
"_id": "5d2708ff79263ba40e54c08d",
"name": "sensor2",
"avg": 0.2222222
}
]
}
It is a little bit confusing after years of working with relational databases.