Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
317 views
in Technique[技术] by (71.8m points)

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

Facing issue to on-going meeting when meeting started it should show meeting until duration present in 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,
    }

What I have tried

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can use $where to use a Javascript function during the evaluation of your query:

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

By the way, if you want to use aggregation in Meteor, you can just access the raw collection like this:

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...