awk awk - 1 month ago 18
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);}
res.json(scores);
});
});

O_Z O_Z
Answer

$orderBy is deprecated try using .sort()

Score.find( {}).sort( { score : -1 } }).exec(function(err, scores) {...