mongooseorderby不工作

我正在build立一个简单的分贝来存储游戏的高分。 现在我想检索高分作为sorting列表。 不幸的是,我不明白为什么下面的代码将无法正常工作,返回的列表不按sorting属性sorting。

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); }); }); 

$orderBy被弃用尝试使用.sort()

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

$orderBy被弃用试试这个..

 mongoose.model('modelName').find().sort({ name: 'asc' }).exec(function(err, con) { console.log(con); });