This question is already asked, but that not solve my issue.
In my Node.Js project i want to user SELECT Query
inside forEach
but that not working properly.
I refer some blog they say use async and await
i tried but that also not working properly.
This is my code:
db.sequelize.query(query, { type: sequelize.QueryTypes.SELECT} ).then(async dataList=>{
let cubbersIdList = [];
// dataList = [{"cubbersId": 27},{"cubbersId": 28},{"cubbersId": 29}]
await dataList.forEach((value, key)=>{
CubbersShopsData.findAndCountAll({where:{cubbersId:value.cubbersId}}).then(datas=>{
cubbersIdList.push(datas);
console.log("---data---");
}).catch(error=>{
logger.error(error);
res.status(200).send({status: 'error', resCode:403, msg:'Internal Server Error...!', data:error});
});
});
console.log("---data---");
res.send(cubbersIdList); // get result here
console.log(cubbersIdList);
});