I need your help for a "simple" problem but the promise is again a mistake for me...
This is un exemple of my code.
// In a middleware, i have a mongoose request
Request
.find({ user: req.user.email })
.then(function (allDatasets) {
allDatasets.forEach(function (oneDataset) {
if (oneDataset.use_case == reqParams.use_case) {
res.status(400).json({
'msg': 'My response'
})
}
})
})
// And my code continue...
I would like that if if condition is true, node return this response and stop the code ! But.. Node is asynchronous and while my loop is running, the code below is executed.
I tried to put the code below in a .then () but it does not wait for the end of the loop to continue to execute the code ...
Thank you for your help