To get the latest and oldest record in Node Mongoose.js, we use the sort
method.
For instance, we write
Tweet.findOne()
.sort("-created_at")
.exec((err, post) => {
//...
});
to call sort
to sort the results by the created_at
field in descending order.
Then we get the latest result from post
in the callback.