title: Result mismatch between elem match, and greater than and less than in mongodb
body: <p>I have a document like this below</p>
  
  <pre><code>{
      "_id" : ObjectId("56df07927a65825b47d5e77d"),
      "internal_id" : 67627,
      "created_at" : ISODate("2015-12-14T16:10:11.015Z"),
      "updated_at" : ISODate("2016-01-16T12:40:57.328Z"),
      "name" : "DPA_Top Brands",
      "company_id" : 2,
      "ad_account_id" : 15,
      "created_time" : ISODate("2015-12-14T15:51:47.000Z"),
      "daily" : [ 
          {
              "fb_impressions" : 1335,
              "fb_clicks" : 93,
              "fb_spend" : 1098.3499999999999091,
              "timestamp" : "2015-12-16"
          }, 
          {
              "fb_impressions" : 5072,
              "fb_clicks" : 475,
              "timestamp" : "2016-01-19"
          }, 
          {
              "fb_impressions" : 322,
              "fb_clicks" : 37,
              "timestamp" : "2016-01-16"
          }
      ]
  }
  </code></pre>
  
  <p>This does not return the above document</p>
  
  <pre><code>db.getCollection('ads').find({'ad_account_id': 15, 'daily': {'$elemMatch': {'timestamp': {'$lte': '2016-01-15', '$gte': '2016-01-01'}}}})
  </code></pre>
  
  <p>But this returns the above document</p>
  
  <pre><code>db.getCollection('ads').find({'ad_account_id': 15, 'daily.timestamp': {'$lte': '2016-01-15', '$gte': '2016-01-01'}})
  </code></pre>
  
  <p><strong>The above query is clearly incorrect, and should not return data as no data is between the two dates.</strong></p>
  
  <p>I believe its the timestamp with '2015' which is really messing up things, but I don't get why. Why is the result of the two different? The elem-match is clearly correct.</p>
  
  <p>Attached output</p>
  
  <p>MongoDB shell version: 3.2.1
  connecting to: test</p>
  
  <pre><code>&gt; db.getCollection('ads').find({'ad_account_id': 15, 'daily.timestamp': {'$lte': '2016-01-15', '$gte': '2016-01-01'}})
  { "_id" : ObjectId("56df07927a65825b47d5e77d"), "internal_id" : 67627, "created_at" : ISODate("2015-12-14T16:10:11.015Z"), "updated_at" : ISODate("2016-01-16T12:40:57.328Z"), "name" : "DPA_Top Brands", "company_id" : 2, "ad_account_id" : 15, "created_time" : ISODate("2015-12-14T15:51:47Z"), "daily" : [ { "fb_impressions" : 1335, "fb_clicks" : 93, "fb_spend" : 1098.35, "timestamp" : "2015-12-16" }, { "fb_impressions" : 5072, "fb_clicks" : 475, "timestamp" : "2016-01-19" }, { "fb_impressions" : 322, "fb_clicks" : 37, "timestamp" : "2016-01-16" } ] }
  &gt; db.getCollection('ads').find({'ad_account_id': 15, 'daily': {'$elemMatch': {'timestamp': {'$lte': '2016-01-15', '$gte': '2016-01-01'}}}})
  &gt; 
  </code></pre>
  
  <p>Thanks in advance</p>