let connectionIDs = [];
_.each(connections, async connection => {
let id = connection.id;
let connector = await UserProfile.findOne({phoneNumber: id});
connectionIDs.push({
name: connector.name.split(" ")[0],
imageID: connector.imageID,
phoneNumber: connector.phoneNumber
})
});
console.log(connectionIDs) //// []
It always returns empty connectionIDs. ie. It does not wait for loop to finish.
What am I missing, I tried appending await with loop i.e await _.each(... and tried wrapping the loop inside Promise.all(.. But I think I am not clear with basics and I hope I can clear the concepts much with this example.