title: What is the efficient way to store date in mongodb.?
body: <p>I have a JSON file which has 40k documents, each document contains a date field. I need to query within Java with dates to retrieve data, so I stored the date in numberLong format.</p>
  
  <pre><code>Date dt = new Date();
  SimpleDateFormat format = new SimpleDateFormat("MM/dd/yyyy");
  dt = format.parse(nextLine[j]);
  document.put(ColumnNameAsKey[j], dt.getTime());
  </code></pre>
  
  <p>where the above code is done in for loop in an API to store data to mongo. 
  But after entering all those data, and then when I queried numberlong changes automatically for the same date, so that I am unable to retrieve all data for the required date. My query to retrieve is </p>
  
  <pre><code>querygraph.put("Complaint Date (MM/DD/YYYY)", new 
      BasicDBObject("$gte",startdate.getTime()).append("$lte",EndDate.getTime()));
  </code></pre>
  
  <p>for eg : if the date 08/01/2012 contains large number of document, the correct numberlong for the date 08/01/2012 is replaced in the date field in mongo. this will continue, but aftr some number of documents, the numberlong keep on changing.. ie if NumberLong is 134353300000 for the date 08/01/2012, then after 6 or more document the numberlong will be different from the former one.. causing unable to retrieve exact data for the date 08/01/2012.. 
  What makes the difference here?</p>