我想为Transactions集合创建流星反应聚合.
交易有日期,所以我想按月汇总数据.
代码是:
ReactiveAggregate(this, Transactions, [
{
$match: {
'date': {
$gte: new Date(startDate),
$lt: new Date(endDate)
}
}
},
{
'$group' :
{
'_id' : { month: { $month: "$date" }},
'totalProfit': { $sum: "$totalProfit"},
'totalSales': { $sum: "$totalSales" },
'totalExpenses': { $sum: "$totalExpenses" },
count: { $sum: 1 }
}
},
{
'$project':{
date: '$date',
totalProfit: '$totalProfit',
totalSales: '$totalSales',
totalExpenses: '$totalExpenses',
}
}
], { clientCollection: "report3MonthsTransactions" });
});
Run Code Online (Sandbox Code Playgroud)
当我这样做时,它会提示错误:
错误:Meteor当前不支持ObjectID以外的对象作为ID
谢谢!