title: Using $match to filter by dates using PHP MongoDB Aggregation Framework
body: <p>I've been trying to use the PHP MongoDB driver with the aggregation framework to filter over a few dates before piping into a $group, but the match isn't doing any filtering on dates, yet it works perfectly when filtering on strings and ints.</p>
  
  <p>Here's my pipeline array and code:</p>
  
  <blockquote>
  <pre><code>  $date = new DateTime();
      $date-&gt;sub(new DateInterval('PT' . $hours . 'H'));
      $mdate = new MongoDate($date-&gt;getTimestamp());
      $ops = array(
          array('$match') =&gt; array(
              'whenField' =&gt; array(
                  '$gt' =&gt; $mdate
              )
          )
      );
  </code></pre>
    
    <p>$results = $this->collection->aggregate($ops);</p>
  </blockquote>
  
  <p>This should return all documents in my collection where 'whenField' is in the last 3 hours, but it returns every document in my collection. I can then switch the '$gt' to an '$lt' and it also returns every document in the collection. I've put this exact same match array as a filter and used <code>find($filter)</code> and it correctly filters. Are Date comparisons incompatible with the aggregation framework $match or have I made some kind of error?</p>