1

I need get Firestore document in forEach loop. But I get error: 'await' expressions are only allowed within async functions and at the top levels of modules

How to get document in forEach loop?

querySnapshot.forEach(queryDocumentSnapshot => {
  const doc = await admin
    .firestore()
    .collection('Collection')
    .doc(queryDocumentSnapshot.id)
    .get();
 
  if (doc.id) {
   // ...
  }
}
Olian04
  • 6,480
  • 2
  • 27
  • 54
FlutterFirebase
  • 2,163
  • 6
  • 28
  • 60
  • 4
    Does this answer your question? [Using async/await with a forEach loop](https://stackoverflow.com/questions/37576685/using-async-await-with-a-foreach-loop) – tomdaly Oct 08 '20 at 12:59
  • @tomdaly Thanks for reply! No it not answer. If I use `for (const queryDocumentSnapshot of querySnapshot) {` it give error: `Type 'QuerySnapshot' must have a '[Symbol.iterator]()' method that returns an iterator.` – FlutterFirebase Oct 08 '20 at 15:37

0 Answers0