Back
I find no doc for the sort modifier. The only insight is in the unit tests: spec.lib.query.js#L12
writer.limit(5).sort(['test', 1]).group('name')
But it doesn't work for me:
Post.find().sort(['updatedAt', 1]);
You can use the below-mentioned code to sort in MongoDB :-
News.find({ deal_id:deal._id}, ['type','date_added'], { skip:0,limit:10, sort:{ date_added: -1 } }, function(err,allNews){ socket.emit('news-load', allNews); })
News.find({
deal_id:deal._id
},
['type','date_added'],
{
skip:0,
limit:10,
sort:{
date_added: -1
}
function(err,allNews){
socket.emit('news-load', allNews);
})
For Mongoose 3.8.x, sorting can be done with the help of the following syntax:
model.find({ ... }).sort({ field : x}).exec(function(err, model){ ... });
Where x can be either:
asc
desc
ascending
descending
1
-1
31k questions
32.8k answers
501 comments
693 users