Here is a snippet of my code:
for( const phase of user.phases) {
for (const schedule of phase.schedules) {
const populatedSchedule = await db.collection('calendar').find({_id: schedule.calendar_id});
console.log('populatedSchedule')
console.log(populatedSchedule.toArray()) // THIS IS A PENDING PROMISE...WHY??
}
}
Note: the code above is in an async function.
I have a nested for-of. I expected the nested loop to "await" the result of db.collection.find. However, an unresolved promise is returned.
I thought for-of loops executed sequentially and would wait for the previous loop to finish, however I think the outer loop isn't allowing the nested loop to resolve the await.