我找不到排序修饰符的文档。唯一的见解是在单元测试中: spec.lib.query.js#L12
writer.limit(5).sort(['test', 1]).group('name')
但这对我不起作用:
Post.find().sort(['updatedAt', 1]);
最佳答案
在 Mongoose 中,可以通过以下任何一种方式进行排序:
Post.find({}).sort('test').exec(function(err, docs) { ... });
Post.find({}).sort([['date', -1]]).exec(function(err, docs) { ... });
Post.find({}).sort({test: 1}).exec(function(err, docs) { ... });
Post.find({}, null, {sort: {date: 1}}, function(err, docs) { ... });
https://stackoverflow.com/questions/4299991/