2015-09-09 38 views
3

我對我的船帆應用面臨的一個問題排序數字帆水線:做一個排序與

我試圖做排序使用對象的水線,但它似乎被分類爲一個字符串,而不是一個整數。

這裏是我的oject:

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,就像這個參數是一個字符串一樣。

我嘗試了許多組合,但都沒有工作。 有沒有人有關於它的想法?

預先感謝您!

克里斯托夫

回答

2

,我發現我的錯誤:我在我的數據庫列「公共秩序」被設定爲VARCHAR類型而不是整數。

希望它可以幫助別人!

再見