Home > database >  How to loop between documents of a collection in firebase firestore?
How to loop between documents of a collection in firebase firestore?

Time:08-08

Is it possible to loop between documents of a collection in the firebase firestore? I have a collection which contains multiple documents with random IDs, and I want to get all these documents and display them.

What I mean is that if I had 10 documents, I want to loop between them and show each document data on the page, like when we use the for loop:

let i;

for (i = 0; i < doc /* 10 */; i  ) {
    document.body.innerHTML  = // document data
}

It will be fine if there is a way to make it without using the for loop.

CodePudding user response:

The Firebase documentation has a pretty good example of reading all documents from a collection. The exact syntax depends on the SDK version you use, so I recommend starting with the examples there and then tuning them to your needs.

  • Related