Express - return certain documents with named route parameters using axios Express - return certain documents with named route parameters using axios mongoose mongoose

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