My URL is coming like this http://localhost:3000/menus/5.5
and it is bringing all the records of 5.5, but I would like the URL to be http://localhost:3000/menus?price=5.5
to have the same result, as you can see below;
Thecodethatmakesthequeryisthis;
functiongetMenus(req,res){varprice=req.params.price;Menus.find({price}).exec((err,menu)=>{if(err){res.status(500).send({message:'Errornasolicitação'});}else{if(!menu){res.status(404).send({message:'NãoexistenenhumReviewsnesseregistro'});}else{res.status(200).send({menu});}}})}
Helpmefixmydrivercode.I'mnotabletogetthepricevaluewiththeURLquoted,http://localhost:3000/menus?price=5.5
.
NOTE:Ineedtodothesametestwiththeotherattributesthatarestring.
Intheabovetestweconsideredthiscode;
router.get('/menus/:price',controller.getMenus);
Seethestatement;
Accordingtoimageaboveitisbeingdonewiththepriceattribute,butithastobedonewiththepriceanddescriptionattributesofmyentityinNodeExpress.
===========================UPDATE==========================
Followingthesuggestion,mymethodwaslikethis;
functionpesquisaEspecialMenus(req,res){try{const{price,description}=req.query;letwhere={};if(price){where.price=price;}if(description){where.description={$regex:description,$options:'i'};}constmenu=awaitMenus.findOne(where).exec();//Casonãoencontrenenhumregistroparaabuscaespecificadaif(!menu){constmessage='NãoexistenenhumReviewsnesseregistro';console.error(message);res.status(404).send({message});return;}//Setudocorrerbemres.status(200).send(menu);}catch(e){constmessage='Erronasolicitação.';console.error(e);res.status(500).send({message});}}
Butthesystemisexperiencingawaiterror
Asyoucanseebelow;