title: Mongo query using aggregation for dates
body: <p>In the following query I'm trying to find entries in my <code>articles</code> collection made in the last week, sorted by the number of votes on that article. The <code>$match</code> doesn't seem to work(maybe I dont know how to use it). The following query works perfectly, so its not a date format issue,</p>
  
  <pre><code>db.articles.find(timestamp:{
                  '$lte':new Date(),
                  '$gte':new Date(ISODate().getTime()-7*1000*86400)}
          })
  </code></pre>
  
  <p>But this one doesn't fetch any results. Without the <code>$match</code> it also fetches the required results(articles sorted by votecount).</p>
  
  <pre><code>db.articles.aggregate([
      {
          $project:{
              _id:1,
              numVotes:{$subtract:[{$size:"$votes.up"},{$size:"$votes.down"}]}}
      },
      {
          $sort:{numVotes:-1}
      },
      {
          $match:{
              timestamp:{
                  '$lte':new Date(),
                  '$gte':new Date(ISODate().getTime()-7*1000*86400)}
          }
      }
  ])
  </code></pre>