I would like to take an average value (e.g. speed), over equal periods of time. My object looks like this.
{
"timestamp": {
"$date": {
"$numberLong": "1621088725666"
}
},
"_id": {
"$oid": "63cfaf58fa6253c35bf96042"
},
"readings": {
"Speed": {
"value": 0.010309532284736633,
"unit": "m/s"
},
"Lap": {
"value": 2,
"unit": ""
}
}
}
I have several readings(records) per second, and I would like to take the average value per 1 second.
{
$group: {
_id: {
truncatedOrderDate: {
$dateTrunc: {
date: "$timestamp", unit: "second", binSize: 1
}
},
},
avgSpeed: {
$avg: "$readings.Speed.value"
},
}
},
Can you confirm if this is a valid operation?