获取模板文件中的聚合查询结果(Handlebars)

时间:2018-05-31 08:38:19

标签: mongodb express mongoose handlebars.js

    var agg = [
  {$group: {
    _id: null,
    totalPrice: { $sum: "$itemPrice" }, 
    total: {$sum: 1}
  }}
];
Idea.aggregate(agg, function(err, logs){
  if (err) { 
    return def.reject(err); 
  }
  console.log(logs);
});

这里是模板文件

    {{#each ideas}}
  <div class="card card-body mb-2">

    <h4>{{title}}</h4>
    <p>{{details}}</p>
    <a class="btn btn-dark btn-block mb-2" href="/ideas/edit/{{id}}">Edit</a>
    <form method="post" action="/ideas/{{id}}?_method=DELETE">
      <input type="hidden" name="_method" value="DELETE">
      <input type="submit" class="btn btn-danger btn-block" value="Delete">
    </form>
  </div>
{{else}}
  <p>No video ideas listed</p>
{{/each}}

0 个答案:

没有答案