I want to sort dynamically by example avgTemperature or avgNoise but i cant do var sort = 'avgTemperature'; and get it in the aggregation. Does anyone have tips?
This is the static aggregation code it does only sort by avgTemperature. But i want to dynamically change.
Measurement.aggregate([{
$group: {
_id: "$workplace",
avgTemperature: {
$avg: "$temperature"
},
avgNoise: {
$avg: "$noise"
}
}
}, {
$sort: {
avgTemperature: 1
}
}]);