Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

How to set min price max price parameters in Nodejs Mongodb, and get data from these queries posted through postman.

  if (req.query.max_price && req.query.max_price != "") {
  qry.price = { $lte: req.query.max_price };
}

and

if (req.query.max_price && req.query.max_price != "") {
  qry.price = { $lte: req.query.max_price };
}

But it doesn't follow the parameters given like min_qurey


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
463 views
Welcome To Ask or Share your Answers For Others

1 Answer

first of all, you must parse the query input to Int or Float. here is a sample of the code :

const max = parseInt(req.query.max, 10);
Models.Collection.find({price: {$lte: max}});

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...