I wanted to make an array based on query results from mongodb, after created the array I can not print this outside of for loop here is the code
let results = await model.find({status: 'active'});
let finalResult = [];
results.forEach( async result=> {
let fromDate = new Date(result.validFrom);
query = {
createdAt: {
$gte: fromDate.getTime(),
$lte: toDate.getTime(),
}
}
results1 = await model1.find(query);
results1.forEach(result1=> {
finalResult.push(result1);
})
});
console.log(finalResult);
I am getting an empty array for finalResult log. can you please help me for this?