hi I want to call a function inside the aggregate.
For Example I have a exchange function and I want to call it inside the $sum.
Here is my code but not work.
function exchange(curFrom, curTo, amount) {
var ex = Cpanel.Collection.Exchange.findOne({
base: curFrom
},
{
sort: {_id: -1}
});
return ex.rates[curTo] * amount;
}
Meteor.methods({
getIncome: function (selector) {
var arr = [];
var result = Inex.Collection.Journal.aggregate([
{$unwind: "$transaction"},
{
$match: selector
},
{
$group: {
_id: {
account: "$transaction.account",
name: "$transaction.accountDoc.name",
currency: "$currencyId"
},
result: {$sum: exchange(curFrom,curTo,"$transaction.amount")}
}
}
]);
}
})