let's say I run this query in Mongoose:
Room.find({}, function(err,docs){
}).sort({date:-1});
This doesn't work!
|
Sorting in Mongoose has evolved over the releases such that some of these answers are no longer valid. As of the 4.1.x release of Mongoose, a descending sort on the
For an ascending sort, omit the |
|||||||||||||||||
|
The correct answer is:
|
|||||||||
|
Been dealing with this issue today using Mongoose 3.5(.2) and none of the answers quite helped me solve this issue. The following code snippet does the trick
You can send any standard parameters you need to |
|||
|
I do this:
This will show the most recent things first. |
|||||
|
Should work as well |
|||
|
See if this helps > How to sort in mongoose? Also read this > http://www.mongodb.org/display/DOCS/Sorting+and+Natural+Order |
|||||||||
|