title: Sort the values by Date in mongodb
body: <p>I am new to mongodb and I am trying to sort all my rows by date.  I have records from mixed sources and I trying to sort it separately.  I didn't update the <code>dateCreated</code> while writing into db for some records.  Later I found and I added <code>dateCreated</code>   to all my records in the db.  Say I have total of 4000 records, first 1000 I don't have <code>dateCreated</code>.  Latest 3000 has that column.  Here I am trying to get the last Updated record using <code>dateCreated</code> column.  Here is my code.</p>
  
  <pre><code>db.person.find({"source":"Naukri"}&amp;{dateCreated:{$exists:true}}).sort({dateCreated: 1}).limit(10)
  </code></pre>
  
  <p>This code retruns me some results (from that 1000 records) where I can't see that <code>dateCreated</code> column at all.  Moreover if I change (-1) here <code>{dateCreated: -1}</code> I am getting results from some other source, but not Naukri.</p>
  
  <p>So I need help this cases,</p>
  
  <ol>
  <li><p>How do I sort by <code>dateCreated</code> to get the latest updated record and by sources also.</p></li>
  <li><p>I am using Java API to get the records from Mongo.  I'd be grateful if someone helps me to find how I will use the same query with java also.</p></li>
  </ol>
  
  <p>Hope my question is clear.  Thanks in advance.</p>