title: MongoDB java driver get records where date between and user is
body: <p>From a collection named <strong>"persons"</strong>, I want to retreive all records <strong>where date is between</strong> </p>
  
  <pre><code>"14-11-2014" and "20-11-2014"  &lt;-- These are both in string format (dd-mm-yyyy)
  </code></pre>
  
  <p>AND</p>
  
  <pre><code>user: "Erik"
  </code></pre>
  
  <p><strong>My mongoDB</strong></p>
  
  <pre><code>{
    "_id" : "546c9f26dbeaa7186ab042c4",          &lt;------this one should NOT be retreived
    "Task: "Sometask"                                                because of the user
    "date" : "20-11-2014",
    "user" : "Dean"
  },
  {
    "_id" : "546caef6dbeaa7186ab042c5",          &lt;--------- This one should be retreived
    "task": "A task",
    "date" : "20-11-2014",
    "user" : "Erik"
  }
  {
    "_id" : "546caef6dbeaa7186ab042c5",          &lt;----- This one should NOT be retreived
    "task": "A task",                                         because of the date
    "date" : "13-11-2014",
    "user" : "Erik"
  }
  </code></pre>
  
  <p>I am using java mongo java driver 2.11.3</p>
  
  <p>Maybe there is some solution using BasicDBObject?</p>
  
  <p>I'm very curious.. thanks</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>I'm using:</p>
  
  <pre><code>public static String findTimelines(String begin, String end, String username) throws UnknownHostException, JSONException{
      DBCollection dbCollection = checkConnection("timelines");
      BasicDBObject query = new BasicDBObject();
      query.put("date", BasicDBObjectBuilder.start("$gte", begin).add("$lte",end).get());
      query.put("user", username);
      dbCollection.find(query).sort(new BasicDBObject("date", -1));
      DBCursor cursor = dbCollection.find(query);
      return JSON.serialize(cursor);
  }
  </code></pre>
  
  <p>Does work until you query something like "28-11-2014" to "01-12-2014", It doesn't return anything even though there is a object with date: "30-11-2014". I think this is because of the month change.<br>
  <strong>Also</strong> that object is retreived when you do: "28-11-2014" to "30-11-2014" because of the month staying the same</p>
  
  <p>Please help!</p>