Search code examples
node.jsmongodbmongoosemongoose-schema

I want to fetch API with dynamic values but Mongoose is not taking value


let wid = req.params.wid;

let result = await model.aggregate([
  {
    $match: {
      windo_no: wid,
    }
  },
  {
    $unwind: '$date'
  },
  {
    $match: {
      'date.date': "2022-09-09"
    }
  }
]);

Here it is not taking value of wid but when I console.log(wid);, it is giving value, here wid is int value and same for date, it is string.

I've also tried:

$match: { windo_no: { $eq: wid }

Solution

  •   'date.date':date2.toString()
    

    for string

    windo_no: {$eq: +wid} for int write + before dynamic value you want to give