答案 0 :(得分:0)
您可以在收藏中搜索特定月份内创建的发票,如下所示:
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