I've got a very basic Mongoose aggregate query
Transaction.aggregate().match({
timestamp : {
$gt : time_lower_bound,
$lt : time_upper_bound
}
}).group({
_id : '$currencyFrom',
count : {
$sum : 1
}
}).sort({
count : -1
})
I wanted to make the _id dynamic. But i tried
var field = job.data.field;
Transaction.aggregate().match({
timestamp : {
$gt : time_lower_bound,
$lt : time_upper_bound
}
}).group({
_id : '$' . field,
count : {
$sum : 1
}
}).sort({
count : -1
})
and it doesn't return the correct data, it returns
[ { _id: null, count: 473 } ]
so i'm missing something obvious here.