title: Aggregate from array where date was before today
body: <p>I am trying to aggregate a collection which has an array. In this array, there's a <code>reminders</code> array. The document might look like this:</p>
  
  <pre><code>{
    _id: "1234",
    dates: {
      start: ISODate(),
      end: ISODate()
    },
    reminders: [{
      sendAt: ISODate(),
      status: 'closed'
    }, {
      sendAt: ISODate(),
      status: 'open'
    }]
  }
  </code></pre>
  
  <p>Say the first one is before today and the next one is after today. What I want to do is get the array of all that come before today, OR, an empty array if none came before today. I tried the following aggregation</p>
  
  <pre><code>db.reminders.aggregate([
    { $match: { 'dates.end': { $gt: new Date } } },
    { $unwind: '$reminders' },
    {
      $match: {
        reminders: {
          $elemMatch: {
            sendAt: { $lt: new Date() },
            status: { $ne: 'open' }
          }
        }
      }
    }
  ])
  </code></pre>
  
  <p>However, if there are no reminders before today, it will fail and give nothing back.</p>
  
  <p>Is there a way to construct this structure with mongodb aggregation?</p>
  
  <p>NOTE: I can't use <code>$filter</code> because that is in 3.2</p>