title: How to retrieve an array's last object in an embedded document in Mongoose?
body: <p>I have trouble writing the query to retrieve the last object of the Comments array embedded inside the Story document.</p>
  
  <p>My collection currently looks like this when I do db.stories.find():</p>
  
  <pre><code>{
  "_id" : ObjectId("55d3a39565698bbc68079e31"),
  "author" : "Steven Chen",
  "link" : "COCO",
  "title" : "COCO",
  "date" : ISODate("2015-08-18T21:28:53.629Z"),
  "comments" : [
      {
          "author" : "Steven",
          "text" : "Major",
          "_id" : ObjectId("55d3a39565698bbc68079e32"),
          "date" : ISODate("2015-08-18T21:28:53.632Z")
      },
      {
          "text" : "Canada",
          "author" : "Steven",
          "_id" : ObjectId("55d3a39a65698bbc68079e33"),
          "date" : ISODate("2015-08-18T21:28:58.001Z")
      },
      {
          "text" : "Usa",
          "author" : "Steven",
          "_id" : ObjectId("55d3a39c65698bbc68079e34"),
          "date" : ISODate("2015-08-18T21:29:00.877Z")
      }
  ],
  "__v" : 0
  }
  </code></pre>
  
  <p>I want to get retrieve the last comment based on the date given the _id of the Story document.</p>
  
  <p>The context of my code is that there is a Story post with a list of comments and I want to retrieve the last comment and send it to my client JS as a JSON using ajax so the view can be updated with the newest/latest comment.</p>
  
  <p>In this case, the comment with "text: "Usa" should be the one getting retrieved.</p>
  
  <p>Can someone provide the proper way to do this and it would be even better if you can explain why? Thank you!</p>