流星js.如何汇总同一集合每月的记录 [英] Meteor js. How to sum records per month of the same collection
本文介绍了流星js.如何汇总同一集合每月的记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有发票的集合,在税额"字段中,我必须调用每个月的发票并计算总税额.
I have the collection of invoices, with the tax field, I must call the invoices for each month and calculate the total tax.
我将Momentjs添加到流星中并使用火焰.
I have Momentjs add to meteor and uses blaze.
推荐答案
您可以在集合中搜索特定月份创建的发票,如下所示:
You can search your collection for invoices created in a particular month like so:
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 });
然后您可以找到所有税项:
You can then find the total of the tax fields:
var taxTotal = 0;
var results = cursor.forEach(function(doc) {
//Adds the tax field of each document to the total
taxTotal += doc.tax;
});
有关光标forEach
方法的更多信息,请参见这里
More information on the forEach
method of a cursor can be found here
这篇关于流星js.如何汇总同一集合每月的记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文