Rohit doddapani
Rohit doddapani

Reputation: 21

fetch data from firebase collections inside a collections dynamically in react

I am unable to fetch data from Firestone as I included collections inside collections my firebase looks like shown in image

enter image description here

I am using code as below but I am not getting any output in the console

const db = fire.firestore()
db.collection("MapData").get().then( snapshot => {
   const users = [];
   //console.log(snapshot,snapshot.data());
   snapshot.forEach(doc => {
      console.log(doc);
      doc.forEach(x => {
          console.log(x);
      })
   }
})
.catch(err => console.log(err));

Upvotes: 0

Views: 254

Answers (1)

Doug Stevenson
Doug Stevenson

Reputation: 317352

Firestor queryies are shallow and don't consider documents in subcollections. Your query will only find documents immediately within the MapData collection. It will not find any documents in subcollection nested under it. If you want documents in subcollections, you will have to build a path to the collection using the names of all the collections and documents in the path.

db.collection("MapData").document("GHF...").collection("geometry")

If you don't know the name of the collection, you can't query it.

Upvotes: 1

Related Questions