我的风帆应用程序面临着排序问题:
我正在尝试使用对象上的水线进行排序,但它似乎被排序为字符串而不是整数。
这是我的主题:
module.exports = {
attributes: {
id:{
type:"int",
required:true
},
id_scenario:{
type:"int",
required:true
},
id_commande:{
type:"int",
required:true
},
ordre:{
type:"int"
}
}
};
这是我的代码:
ScenarioCommande.find()
.where({ id_scenario: idScenario })
.sort({ordre: 'ASC'})
.exec(function(err, scenariocommande) {
res.json(scenariocommande);
});
这是输出:
{
"id": "30",
"id_scenario": "12",
"id_commande": "6",
"ordre": "1",
"createdAt": null,
"updatedAt": null
},
{
"id": "37",
"id_scenario": "12",
"id_commande": "18",
"ordre": "10",
"createdAt": null,
"updatedAt": null
},
{
"id": "31",
"id_scenario": "12",
"id_commande": "4",
"ordre": "2",
"createdAt": null,
"updatedAt": null
},
{
"id": "23",
"id_scenario": "12",
"id_commande": "14",
"ordre": "3",
"createdAt": null,
"updatedAt": null
},
...
正如您所看到的,这些对象在“ordre”参数上进行排序,如:1,10,2,3,就像这个参数是一个字符串一样。
我尝试了很多组合,但都没有效果。 有人对此有所了解吗?
提前谢谢!
克里斯托弗
答案 0 :(得分:2)
我发现了自己的错误:我的专栏" ordre"在我的数据库中设置为varchar而不是整数。
希望它有所帮助!
再见