Home > database >  Firestore get roots field of a document
Firestore get roots field of a document

Time:01-07

I do have a firestore database: Firestore database

What I want, is to get to the root of the field "points/0/title". Is it possible somehow?

CodePudding user response:

From what you mentioned in your last comment, you can traverse a document as you would any other Map or dictionary object. The Firestore documentation for Getting documents is a good place to start. As for your nested field, if you would like to get the Title value, you could do it this way, by traversing the dictionary into the points array, then traversing the nested dictionary to the Title value:

const docRef = doc(firestoreDB, "innerArray", "testDoc1");

  const getData = async () => {
    const docSnap = await getDoc(docRef);
    console.log(docSnap.data().points[0].title) //traversing the data obtained from a document
  }

This outputs foo, which is the value for Title in my test document.

  •  Tags:  
  • Related