title: Get elements of an array in date range
body: <p>This is an example document in my MongoDB collection:</p>
  
  
  
  <pre class="lang-js prettyprint-override"><code> var user: [{
              "_id" : ObjectId("5391b11a3c0a9ac01300006d"),
              "injurydata" : {                
                  "injuryinformation" : [ 
                      {
                          "status" : "current",
                          "updateddate" : ISODate("2014-06-06T12:16:20.306Z"),
                          "updatedby" : "",
                          "dateofinjury" : ISODate("2014-06-27T18:30:00.000Z"),                          
                          "_id" : ObjectId("5391b11a3c0a9ac01300006f")
                      }                   
                  ]
              }
           },
           {
              "_id" : ObjectId("5391b11a3c0a9ac01300006d"),
              "injurydata" : {                
                  "injuryinformation" : [ 
                      {
                          "status" : "current",
                          "updateddate" : ISODate("2014-06-06T12:16:20.306Z"),                           
                          "dateofinjury" : ISODate("2014-06-28T18:30:00.000Z"),                            
                          "_id" : ObjectId("5391b11a3c0a9ac01300006f")
                      }                   
                  ]
              }
           },
           {
              "_id" : ObjectId("5391b11a3c0a9ac01300006d"),
              "injurydata" : {                
                  "injuryinformation" : [ 
                      {
                          "status" : "current",                            
                          "dateofinjury" : ISODate("2014-08-10T18:30:00.000Z"),                            
                          "_id" : ObjectId("5391b11a3c0a9ac01300006f")
                      }                   
                  ]
              }
           }]
  </code></pre>
  
  <p>From this document, I want only those <code>injuryinformation</code> array elements for which <code>dateofinJURY</code> is between 2014-06-28 and 2014-06-30, so I will only get first two elements.</p>
  
  <p>I tried this query but I still get the whole array</p>
  
  <pre class="lang-js prettyprint-override"><code>db.user.find(
  {
      $and: 
      [
          {"injury.injurydata.injuryinformation.dateofinjury": 
          {"$gte": ISODate("2014-05-21T08:00:00Z") , "$lt": ISODate("2014-06- 03T08:00:00Z")}},       
          {"_id":ObjectId("538d9a1dd173e5202a00005d")}
      ],
  
  })
  </code></pre>