In Mongoose, how do I sort by date? (node.js)

1.3K    Asked by DavidEdmunds in Devops , Asked on Jul 4, 2021

let's say I run this query in Mongoose:

Room.find({}, function(err,docs){
}).sort({date:-1});

Please help me with solution.

Answered by Gloria Holl

For mongoose sort by date, you can use the below-mentioned code:-

    Blah.find({}).sort({date: -1}).execFind(function(err,docs){ });


Your Answer

Interviews

Parent Categories