【发布时间】:2014-01-29 03:19:58
【问题描述】:
我正在尝试猫鼬聚合。我想获得日期范围内字段的总和。 http://mongoosejs.com/docs/api.html#model_Model.aggregate
mymodel.aggregate({$match:{date:{$gte: fromDate, $lt: toDate}}},
{$project:{_id:0,date:1, count:1}},
{$group:{'_id':0,count:"$count"}}).exec(function(err,data){
if(err){
console.log('Error Fetching model');
console.log(err);
}
callback(false, data);
});
这不起作用。
{ [MongoError: exception: the group aggregate field 'count' must be defined as an expression inside an object]
name: 'MongoError',
errmsg: 'exception: the group aggregate field \'count\' must be defined as an expression inside an object',
code: 15951,
ok: 0 }
有什么想法吗?
【问题讨论】:
标签: node.js mongodb mongoose aggregation-framework