我想根据发生时间查询on-going定义在collection中的持续时间之间的会议

I want to query on-going meeting between the duration defined in collection based on occurrence time

on-going 会议在会议开始时面临问题它应该显示会议直到持续时间出现在 collection。

This is collection of meeting with occurence time of meeting

{
        "status": "ACTIVE",
        "id": 7,
        "uid": 172,
        "title": "meeting with 2 persons",
        "description": "meeting description 3",
        "duration": 3600,
        "participants": [{
            "role": "ORGANIZER",
            "status": "ACCEPTED",
            "uid": 172
        }, {
            "role": "ATTENDEE",
            "status": "PENDING",
            "uid": 173
        }, {
            "role": "ATTENDEE",
            "status": "PENDING",
            "uid": 175
        }],
        "created": {
            "$date": "2019-09-01T12:01:32.000Z"
        },
        "occurrence_time": {
            "$date": "2019-09-02T13:11:38.000Z"
        },
        "created_at": 1605187219,
    }

我试过的

Meetings.find({ 
    'participants.uid': 172,
    status: 'ACTIVE',
    occurrence_time: {
      $gte: new Date(moment().subtract('$duration', 'seconds'))
    }
  }, { 
    sort: { occurrence_time: 1 }
  }).fetch();

您可以使用 $where 在查询评估期间使用 Javascript 函数:

Meetings.find({$where: function() {
    return Date.now() < (new Date(this.occurrence_time.$date)).getTime() + this.duration;
  }
})

顺便说一句,如果你想在 Meteor 中使用聚合,你可以像这样访问原始集合:

Meetings.rawCollection().aggregate([
   // .. aggregation pipeline ..
]);