猫鼬聚合:如何显示ejs聚合的结果

时间:2019-04-13 23:18:59

标签: node.js mongodb mongoose ejs

如何从猫鼬聚合中获取结果并将其与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);
  }

0 个答案:

没有答案