I am getting this error.when i am fetching values from collection, why this error coming. tried many solutions but not working
here is my code please solve this issue
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);
});
}
});
error is :
{ message: 'Cast to number failed for value "undefined" at path "DealID"',
name: 'CastError',
kind: 'number',
value: undefined,
path: 'DealID',
reason: undefined }
var DealStatus = req.params.status; var DealID =req.params.DealID; var SinceID = req.params.SinceID;
please correct these very small mistakes in if-else condition if(DealStatus==1) else if(DealStatus==0)
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments