开发者

MongoDB/Mongoose Sort Error

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜