mongodb聚合填充函数

时间:2014-11-10 10:37:04

标签: node.js mongodb mongoose

我正在使用两个表Event和Instance及其Schema Structure,

活动表:

{
   name:
   description:
   event_instance: {"Schema.Types.ObjectId, ref:'Instance'}
}

实例表:

{
   from_date:
   to_date:
}

我需要通过使用from_date对事件表进行分组来获取计数,方法是使用Event表中的event_instance refObj字段访问实例表。

示例代码:

exports.stats = function(req,res,next){
async.parallel([function(callback){
EventModel.aggregate([{
$match: queryObj
},{
$group:{
_id:{
  "$from_date"     //field from Instance table     
},
count: {
  $sum: 1
}
.....

0 个答案:

没有答案
相关问题