title: update only latest record in mongodb
body: <p>I have a collection in which I store student records, each student might have multiple records. I can query them using studentId and it works fine, and it returns me all the records. </p>
  
  <p>I need to update the latest student record. There is an addedAt field in the collection for each record. How can I write this query?</p>
  
  <p>I am using PHP and my current code is :</p>
  
  <p>`</p>
  
  <pre><code>$criteria = array("studentID"=&gt;"100010", );
  $newdata = array('$set'=&gt;array("status"=&gt;"no")); 
  $options = array("upsert"=&gt;true);
  $ret = $collection-&gt;update(
      $criteria,
      $newdata,
      $options
  );
  </code></pre>
  
  <p>Any help is appreciated!
  `</p>