Here I am first searching for ticket and then train for which ticket is booked. I am new to promises so I want to know this is the right way or it can be done without nesting?
router.get('/ticket/:id', isLoggedIn, (req, res) => {
Ticket.findById(req.params.id)
.populate('passengers')
.exec()
.then(foundTicket => {
Train.findById(foundTicket.trainDetails._id)
.exec()
.then(foundTrain => {
res.render("ticket",{ticket:foundTicket, train:foundTrain});
})
.catch(err => {
console.log(err)
})
})
.catch(err => {
console.log(err)
})
});