2011-04-15 65 views
3
Item.find().sort([['_id','descending']]).limit(15).each(function(doc) { 
    client.send(JSON.stringify(doc)); 
}); 

返回此錯誤:的MongoDB /貓鼬排序錯誤

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

任何想法?謝謝!

回答

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

嘗試.sort([['_id','desc']])

,你也可以嘗試.sort("_id")但默認爲升序排列。

+0

STIL得到這個錯誤`{ 「堆疊」:「錯誤:錯誤:非法排序條款,必須是這樣的形式[ '字段1',「(升序|降序)'],['field2','(升序|降序)']] \ n在[object Object] .nextObject(/opt/local/lib/node/.npm/mongoose/1.1.24/package/支持/ node-mongodb-native/lib/mongodb/cursor.js:460:16)\ n在Array.0(/opt/local/lib/node/.npm/mongoose/1.1.24/package/lib/mongoose /query.js:651:16)\n在EventEmitter._tickCallback(node.js:126:26)「,」message「:」錯誤:非法排序子句必須是[['field1','(升序|降序]'],['field2','(升序|降序)']]「}' – fancy 2011-04-15 16:15:24

0

這應該工作:

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