I am trying to query second table from the response of first table. Since I have to update data for each of the record , I am calling mongoDB query inside loop.
here res is the response of first table, problem is in this line:
const secondRes = await myModel.paginate({name:doc.name});
await is not allowed since loop is synchronous and if I am removing await from this line, it is not giving result even if data is present in DB. if I am moving out db call from loop and directly pasting in getResponse function, I am getting response from database but I need to call within loop, please anyone suggest , how can I solve this.
Thanks in advance.
exports.getResponse = async (req,res)=>{
res.docs.forEach(doc => {
let response1 = {};
const secondRes = await myModel.paginate({name:doc.name});
console.log("SecondRes ::"+JSON.stringify(secondRes));
}
}