【问题标题】:Meteor js. How to sum records per month of the same collection流星.js。如何汇总同一集合的每月记录
【发布时间】:2018-01-09 20:55:08
【问题描述】:

我有发票的集合,有了税金字段,我必须调用每个月的发票并计算总税额。

我将 Momentjs 添加到流星并使用 blaze。

App invoices

【问题讨论】:

    标签: javascript meteor momentjs meteor-blaze


    【解决方案1】:

    您可以像这样在您的集合中搜索特定月份创建的发票:

    var start = new Date(year, month, day);
    var end = new Date(year, month, day);
    
    //Invoices with a 'date' field between the 'start' and 'end' dates
    var cursor = CollectionName.find({ date : { $gte : start, $lt: end });
    

    然后您可以找到税收字段的总数:

    var taxTotal = 0;
    var results = cursor.forEach(function(doc) {
      //Adds the tax field of each document to the total
      taxTotal += doc.tax;
    });
    

    更多关于forEach游标方法的信息可以在here找到

    【讨论】:

      猜你喜欢
      • 2021-02-16
      • 1970-01-01
      • 2014-04-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-25
      • 1970-01-01
      • 2023-01-08
      相关资源
      最近更新 更多