流星js。如何对同一个集合中的每月记录进行汇总

问题描述:

我有发票集合,在税收领域,我必须调用每个月的发票并计算总税额。流星js。如何对同一个集合中的每月记录进行汇总

我有Momentjs加入流星并使用火焰。

App invoices

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

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

+0

谢谢!这帮助我很多! –