Skip to content

Instantly share code, notes, and snippets.

@gistfrojd
Created July 15, 2015 07:26
Show Gist options
  • Save gistfrojd/6b12be2d54c7ca7cb31e to your computer and use it in GitHub Desktop.
Save gistfrojd/6b12be2d54c7ca7cb31e to your computer and use it in GitHub Desktop.
How to perform sorting in mongoose (from http://stackoverflow.com/a/15081087)
Room.find({}).sort('-date').exec(function(err, docs) { ... });
Room.find({}).sort({date: -1}).exec(function(err, docs) { ... });
Room.find({}).sort({date: 'desc'}).exec(function(err, docs) { ... });
Room.find({}).sort({date: 'descending'}).exec(function(err, docs) { ... });
Room.find({}, null, {sort: {date: -1}}, function(err, docs) { ... });
Room.find({}, null, {sort: [['date', -1]]}, function(err, docs) { ... });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment