So I need to make queries using a .map function and then push it to an array and return it but the problem is the array is always empty when returning because its not async, I have tried async/await
but that does not work. An example of my code would be like this:
let arrayToSend = []
anotherArray.map(obj => {
Model.findOne({_id: id}).exec(function(err, result){
if (!err) {
arrayToSend.push(result)
} else {
let anotherObj = {key: value}
arrayToSend.push(anotherObj)
}
})
}
return res.json({arrayToSend})