流星js。如何对同一个集合中的每月记录进行汇总
答
您可以搜索集合在一个特定的月份创建,像这样的发票:
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
谢谢!这帮助我很多! –