【问题标题】:I want to query on-going meeting between the duration defined in collection based on occurrence time我想根据发生时间查询集合中定义的持续时间之间的持续会议
【发布时间】:2021-04-17 08:40:35
【问题描述】:

在会议开始时面临正在进行的会议的问题,它应该在集合中显示会议直到持续时间。

这是会议发生时间的集合

{
        "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();

【问题讨论】:

  • 我正在使用流星,它不允许使用聚合
  • 已经试过了.. 包已经过时了

标签: mongodb mongoose meteor mongodb-query


【解决方案1】:

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

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

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-07
    • 1970-01-01
    相关资源
    最近更新 更多