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));
});
精彩评论