Express - return certain documents with named route parameters using axios
Client-side:
axios.get('/api/orders/' + this.props.user.name) .then(function (response) { // handle success console.log(response); }) .catch(function (error) { // handle error console.log(error); })
- You need to handle the Promise when resolved/rejected.
Server-side:
router.get('/orders/:name', function(req, res) { return Order.find({name: req.params.name}).then(function(orders) { // return orders when resolved res.send(orders); }) .catch(function (error) { // handle error console.log(error); })});
You did not specify a named route parameter in your route path.
You also aren't accessing the
name
property by usingreq.params
only.You should use
Model.find()
conditions parameter to specify which document[s] you're trying to find.Query.prototype.select()
is for filtering document fields.