Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
459 views
in Technique[技术] by (71.8m points)

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

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


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

1 Answer

0 votes
by (71.8m points)

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}});

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...