简体   繁体   English

Firestore 获取文档的根字段

[英]Firestore get roots field of a document

I do have a firestore database:我确实有一个 Firestore 数据库: Firestore 数据库

What I want, is to get to the root of the field "points/0/title" .我想要的是到达字段"points/0/title"的根。 Is it possible somehow?有可能吗?

From what you mentioned in your last comment, you can traverse a document as you would any other Map or dictionary object.根据您在上一条评论中提到的内容,您可以像遍历任何其他Map或字典 object 一样遍历文档。 The Firestore documentation for Getting documents is a good place to start. 获取文档的 Firestore 文档是一个很好的起点。 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:至于您的嵌套字段,如果您想获取Title值,您可以这样做,通过将字典遍历到points数组中,然后将嵌套字典遍历到Title值:

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.这将输出foo ,这是我的测试文档中Title的值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM