如何从猫鼬聚合中获取结果并将其与ejs显示在一起?
这是我的代码:
Record.aggregate(
[
{
$group:
{
_id: { month: { $month: "$date"}, year: { $year: "$date"} },
totalExpense: { $sum: "$amountExpense"},
totalIncome: { $sum: "$amountIncome"},
count: { $sum: 1 }
}
},
{ "$project": {
"total": { "$subtract": [ "$totalIncome", "$totalExpense" ] }
}},
{
$out: "total"
}
]), function(err, results) {
console.log(results);
res.json(results);
}