mongoose查询按时间排序

2018-11-01 16:59   Tags:
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({}).sort([['date', -1]]).exec(function(err, docs) { ... });
Room.find({}, null, {sort: '-date'}, function(err, docs) { ... });
Room.find({}, null, {sort: {date: -1}}, function(err, docs) { ... });

如果用后面的几种方法,第二个参数,如果没有必须填写null,否则报错,

更多:https://stackoverflow.com/questions/5825520/in-mongoose-how-do-i-sort-by-date-node-js