Meteor MongoDB: How to aggregate date-range with computed end-date from collection field?
<p>I'm using meteorhacks:aggregate package for Meteor, and I'm trying to find Events within a date-range between:</p>

<ul>
<li>now, minus one day.</li>
<li>the end-date of the Event, plus two weeks.</li>
</ul>

<p>Problem is, the end-date is stored in the Event document, in a field at <code>times.until</code>. The Event document looks like this:</p>

<pre><code>// Event collection doc:
{
  _id: 'abc',
  times: {
    start: {
      dateTime: "ISODate("2017-03-07T00:00:00Z"),
      timeZone : "America/Chicago"
    },
    until: "20170307T000000Z"
  }
}
</code></pre>

<p>I able to aggregate to find dates in a range, but I can't figure out how to compute an end-date for the range based on the Event's <code>times.until</code> field.  </p>

<pre><code>if (Meteor.isServer) {
  Meteor.methods({
    'events.inProgress'() {
      const start = moment().utc().subtract(1, 'day').toDate();

      return Events.aggregate([
        {$match: {"times.start.dateTime": {$gt: start, $lt: end**(MUST COMPUTE end FROM DOC'S times.until PLUS 2 WEEKS)**}}},
      ]);
    }
  }
}
</code></pre>

<p>Also, note the format of the <code>times.until</code> field is <code>20170307T000000Z</code> (not sure the correct name of this format). This is not a valid format for a JavaScript <code>Date</code>, but moment.js handles this String no problem.  With access to the <code>times.until</code> field, I can do:</p>

<pre><code>const end = moment(event.times.until).add(2, 'week').toDate();
</code></pre>

<p>This does give me the correct end-date of the range, but how can I grab the <code>times.until</code> field to compute the end-date while constructing the pipeline?</p>