I am using MongoDB with Node.JS. I have a collection which contains a date and other rows. The date is a JavaScript Date object.
Date
How can I sort this collection by date?
Just a slight modification to @JohnnyHK answer
collection.find().sort({datefield: -1}, function(err, cursor){...});
In many use cases we wish to have latest records to be returned (like for latest updates / inserts).
2.1m questions
2.1m answers
60 comments
57.0k users