2017-01-04 116 views
1

我得到這個錯誤。當我從集合中獲取值時,爲什麼會出現這個錯誤。嘗試了多種解決方案,但沒有工作message:'Cast to number failed for value「undefined」in nodejs mongoose express

這裏是我的代碼,請解決這個問題

apiRoutes.get('/getdeals/:status/:DealID/:SinceID' , function(req, res, next) { 
    var DealStatus = req.status; 
    var DealID =req.DealID; 
    var SinceID = req.SinceID; 

    if(DealStatus==1){ 
     Adddeal.find({ 
     $and: [ 
      { DealID: { $gt: SinceID }}, 
      { DealStatus: {$eq: 1}} 
     ] 
    }, function (err, results) { 
     if (err) return console.error(err); 
     res.json(result); 
    }); 
    }else if(DealStatus==0){ 
     Adddeal.find({ 
     $and: [ 
      { DealID: { $gt: SinceID }}, 
      { DealStatus: {$eq: 0}} 
     ] 
    }, function (err, results) { 
     if (err) return console.error(err); 
     res.json(result); 
    }); 
    }else{ 
      Adddeal.find({ 
      DealID: { $gt: SinceID } 
    }, function (err, results) { 
     if (err) return console.error(err); 
     res.json(result); 
    }); 
    } 
}); 

錯誤是:

{ message: 'Cast to number failed for value "undefined" at path "DealID"', 
    name: 'CastError', 
    kind: 'number', 
    value: undefined, 
    path: 'DealID', 
    reason: undefined } 

回答

0

var DealStatus = req.params.status; var DealID =req.params.DealID; var SinceID = req.params.SinceID; 請糾正這些非常小的失誤的if-else條件 if(DealStatus==1) else if(DealStatus==0)

+0

其獲取錯誤狀態未定義 – saiibitta

+0

您是否通過url cor rectly-> ..../getdeals/1 /.../.../或..../getdeals/0 /.../.../ –

+0

正確無誤@Riya Saxena – saiibitta

相關問題