title: How to compare two dates in the mongo aggregation framework?
body: <p>We're currently using metabase to analyze our data. I've run into a problem with querying with an aggregation query. I wanted all the documents where date1 is before date2. (I used 3 filters to debug my results, it should be possible to put it in 1 match filter later on)</p>
  
  <pre><code>[{
    "$match": {
      "date1": {
        "$exists": true
       }
    }
  }, {
    "$project": {
      "_id": 0,
      "date1": 1,
      "date2": 1
    }
  }, {
    "$match": {
      "date1": {
          "$lt": "$date2"
      }
    }
  }]
  </code></pre>
  
  <p>I'm always getting no results. Anybody who could help me with the query?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>The documents looks like this:</p>
  
  <pre><code> { 
     _id: ObjectID,
     date1: ISODate("2016-10-04T08:34:15.041Z"),
     date2: ISODate("2016-10-05T08:34:15.041Z")
     ... some more fields that are not interesting for this query
   }
  </code></pre>
  
  <p>There are around 50k documents in the collection.</p>