message: 'Cast to number failed for value "undefined" at path in nodejs mongoose express

saiibitta

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 }
Riya Saxena

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.

edited at
0

Comments

0 comments
Login to comment

Related

mongoose : findByIdAndUpdate through erro "message":"Cast to string failed for value \"undefined\"

mongoose CastError: Cast to undefined failed for value "[object Object]" at path "apps"

mongoose - CastError: 'Cast to undefined failed for value "[object Object]" at path "trainers"

mongoose - Cast to number failed for value "[object Object]" at path

CastError: Cast to ObjectId failed for value In mongoose with NodeJs

Cast to ObjectID failed for value at path in mongoose

"Cast to Number failed for value " (type Object) - Mongoose

Discord.JS/Mongoose Error: UnhandledPromiseRejectionWarning: CastError: Cast to Number failed for value "NaN" at path "cashBalance"

Mongoose.js CastError: Cast to Number failed for value "{ '$gte': 1 }" at path "access" for model "Projekt"

Node Express Mongoose : Problem with Number value Undefined

Mongoose: CastError: Cast to embedded failed for value "{ value: 'x' }" at path "items"

Cast to undefined failed for value "[object Object]" at path in node.js

Cast to ObjectId failed for value "undefined" at path "_id" for model "User"

Mongoose Cast to ObjectId failed for value

Cast to Number failed for value "NaN" at path error solved by server self

Cast to number failed for value - GraphQL

What's Mongoose error Cast to ObjectId failed for value XXX at path "_id"?

Mongoose: 'Cast to embedded failed for value at path. Cannot use 'in' operator to search for '_id'

MongoDB/Mongoose CastError: Cast to string failed for value (type Object) at path "field"

UnhandledPromiseRejectionWarning: CastError: Cast to string failed for value in mongoose

Mongoose - CastError Cast to string failed for value "Object"

Cast to ObjectId failed for value "undefined" (type string) at path "_id" for model "card"

UnhandledPromiseRejectionWarning: CastError: Cast to ObjectId failed for value "undefined" at path "_id" for model "User"

How do I solve "CastError: Cast to ObjectId failed for value "undefined" (type string) at path "_id" for model "Task""?

CastError: Cast to ObjectId failed for value "n" (type number) at path "propertyArray.$"

Cast to ObjectId failed for value at path "_id" for model

Cast to ObjectId failed for value "" at path "_id" for model

Cast to ObjectId failed for value " " at path "_id" for model

CastError: Cast to ObjectId failed for value "" at path "_id"