Is there a way I can use mongoose function inside a forEach loop like this example ? making use of the counter and reach the reachable line
idsArray.forEach((itemId,i) =>{
Place.findById(itemId,(err,item)=>{
if(err){
console.log("error")
}
idsArray[i] = {item.id}; // unreachable
})
})
I read about Async but I couldn't know the way to achieve it through it
if (error)statement, that could be one of the reasons you can't access to item.id. Maybe the query is failing but as you are not returning it keeps going even if there it was an error and item is undefined or null