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