Promise has no method 'sort'

妖精的绣舞 提交于 2019-12-05 19:08:59

Try this

return Item.find({item_id: "03010200400000a0bf00210"}).sort({ts:-1}).limit(1).execAsync();
var options = {
        sort: { ts: -1 },
        limit: 1
    };    
var query = {item_id: "03010200400000a0bf00210"};
Item.findAsync(query,null,options).then(function(data){
     console.log(data);
    }).catch(function(err){
     console.log(err);
    });

Assuming Item.findAsync is returning a promise, and not the actual results, you need to wait until the results are returned before you sort them...

return Item.findAsync({item_id: "03010200400000a0bf00210"})
    then(function(items) {
        return items.sort({ts:-1}).limit(1);
    });
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!