简体   繁体   中英

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));
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM