awk awk - 1 year ago 167
Node.js Question

Mongoose orderby not wokring

I'm building a simple db to store the highscore of a game.
Now I would like to retrieve the highscore as sorted list.
Unfortunately I can't figure out why the following code won't work, the returned list is not sorted by the score property.

var mongoose = require('mongoose');
var Score = mongoose.model('Score');

router.get('/', function(req, res, next) {
Score.find( { $query: {}, $orderby: { score : -1 } } , function(err, scores) {
if (err) {return next(err);}

Answer Source

$orderBy is deprecated try using .sort()

Score.find( {}).sort( { score : -1 } }).exec(function(err, scores) {...
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download