title: Spring Data MongoDB Date between two Dates
body: <p>i'm using Spring Data for MongoDB and got the following classes</p>
  
  <pre><code>class A {
      List&lt;B&gt; b;
  }
  
  class B {
      Date startDate;
      Date endDate;
  }
  </code></pre>
  
  <p>when i save an object of A it gets persisted like</p>
  
  <pre><code>{
      "_id" : "DQDVDE000VFP8E39",
      "b" : [
            {
                "startDate" : ISODate("2009-10-05T22:00:00Z"),
                "endDate" : ISODate("2009-10-29T23:00:00Z")
            },
            {
                "startDate" : ISODate("2009-11-01T23:00:00Z"),
                "endDate" : ISODate("2009-12-30T23:00:00Z")
            }
      ]
  }
  </code></pre>
  
  <p>Now i want to query the db for documents matching entries in b where a given date is between startDate and endDate.</p>
  
  <pre><code>Query query = new Query(Criteria.where("b").elemMatch(
      Criteria.where("startDate").gte(date)
      .and("endDate").lte(date)
  );
  </code></pre>
  
  <p>Which results in the following mongo query: </p>
  
  <pre><code>{
     "b": {
         "$elemMatch": { 
             "startDate" : { "$gte" : { "$date" : "2009-11-03T23:00:00.000Z"}}, 
             "endDate" : { "$lte" : { "$date" : "2009-11-03T23:00:00.000Z"}}
         }
     }
  }
  </code></pre>
  
  <p>but returns no resulting documents. Does anybody know what i'm doing wrong? I don't get it...</p>
  
  <p>Thank you very much in advance!!</p>