My current implementation doesn't work because the console.log for "after" is executing before the .map iteration on querySnapshop.docs has finished. In my console I see "before", "after", and then "removing..."
How do I rework this to have the correct execution order?
const uid = this.afAuth.auth.currentUser.uid;
let pollIds = polls.map(poll => poll.payload.doc.id);
console.log("before", pollIds);
var db = firebase.firestore();
db.collection('votes').where('uid', '==', uid).get({source: 'server'}).then((querySnapshot) => {
let totalVotes = querySnapshot.docs.length;
let alreadyVoted = querySnapshot.docs.map(async vote => {
vote.ref.get().then(doc => {
let pollId = doc.data().poll
var index = pollIds.indexOf(pollId);
if (index > -1) {
console.log("removing...", pollIds[index]);
pollIds.splice(index, 1);
}
});
});
console.log("after", pollIds);
});
Promise.all()the map