I'm trying to switch to Promise from forEach because of asynchronousness.
I've tried:
const ref1 = await firestore.collection("collection").get();
await Promise.all(ref1.map(async (doc) => {
// ...
}));
But it throwns : TypeError: ref1.map is not a function.
(I'd like to loop through ref1 documents)
CodePudding user response:
ref1 is a QuerySnapshot that does not have a map() function. It has a docs property that is an array of QueryDocumentSnapshot. Try:
const ref1 = await firestore.collection("collection").get();
const data = ref1.docs.map((doc) => {
return { id: doc.id, ...doc.data() }
}));

