Skip to content Skip to sidebar Skip to footer

Retrieve Data From Multiple Documents From Firestore

I tried a lot of times but I am still not able to retrieve data from multiple documents, The below screenshot shows that I have 3 documents in my collection and my question is how

Solution 1:

The snapshot object contains all the 3 documents in your collection. You must iterate over all and render data to your HTML as explained below.

db.collection("Policies List").get().then((snapshot) => {
  const documents = snapshot.docs//array of documents
  documents.forEach((doc) => {
    const docData = doc.data() //Data of that single documentconsole.log(docData)
    renderToHtml() // Code that creates new HTML elements
  })
})

This way you are creating new HTML elements for all the documents in your collection. The renderToHtml() function will contain that .innerHTML code. Please make sure to see the logs in the console. They'll help understand the structure in a better way.

Post a Comment for "Retrieve Data From Multiple Documents From Firestore"