Home > database >  Promise.all(ref.map(async (file) => ref1.map is not a function
Promise.all(ref.map(async (file) => ref1.map is not a function

Time:10-28

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)

Complete code: enter image description here

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() }
}));
  • Related