1
我正在尝试猫鼬聚集。我想获得日期范围内的字段总数。 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 }
任何想法?
谢谢:)它工作:) – Neo