Answers for "sort mongoose response"

3

mongoose find sort

Post.find({}).sort('test').exec(function(err, docs) { ... });
Post.find({}).sort([['date', -1]]).exec(function(err, docs) { ... });
Post.find({}).sort({test: 1}).exec(function(err, docs) { ... });
Post.find({}, null, {sort: {date: 1}}, function(err, docs) { ... });
Posted by: Guest on February-26-2021
1

sort mongoose response

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

-1 for descending & 1 for ascending
Posted by: Guest on March-17-2021

Browse Popular Code Answers by Language