开发者

MongoDB/Mongoose Sort Error

开发者 https://www.devze.com 2023-02-26 16:44 出处:网络
Item.find().sort([[\'_id\',\'descending\']]).limit(15).开发者_高级运维each(function(doc) { client.send(JSON.stringify(doc));
Item.find().sort([['_id','descending']]).limit(15).开发者_高级运维each(function(doc) {
  client.send(JSON.stringify(doc));
});

Returns this error:

Error: Error: Illegal sort clause, must be of the form [['field1', '(ascending|descending)'], ['field2', '(ascending|descending)']]\n

Any ideas? Thanks!


Item.find().sort('_id','descending').limit(15).each(function(err, doc) {
client.send(JSON.stringify(doc));
});


try .sort([['_id','desc']])

Also you can try .sort("_id") but that defaults to ascending order.


This should work:

Item.find().sort([['_id','1']]).limit(15).each(function(err, doc) {
  client.send(JSON.stringify(doc));
});
0

精彩评论

暂无评论...
验证码 换一张
取 消