angularjs - Passing two parameters to Express Mongoose api to return single result -
i'm new creating apis express , mongoose.
i've been able setup basic endpoints, get, post, put, etc.
but want set 1 pass 2 parameters search collection , return single result.
i don't think i'm passing parameters correctly.
in angular, have following service call, know correct:
.factory('loginfactory', function($resource){ return $resource('/api/user?email=:eml&password=:pwd', {}, { query:{ method:'get', isarray:true, params:{ eml:'@eml', pwd:'@pwd'}} }); });
but don't think i'm doing right in express/mongoose api. here endpoint:
router.route('/:email:password') .get(function(req, res){ user.findone({email:req.param.email, password:req.param.password}, function(err, user){ if(err) res.send(err); res.json(user); }); });
i use req.params
not req.param
and have slash before each param
app.get("/:email/:password", function(req, res){ console.log(req.params.email) console.log(req.params.password) })
this property object containing properties mapped named route “parameters”. example, if have route /user/:name, “name” property available req.params.name. object defaults {}.
you have 1 paramater looks :email:password
. got add slash create url segment express can recognize route paramater.
Comments
Post a Comment