【问题标题】:Is it possible to get a collection inside a document along with all the other doc data?是否可以在文档中获取集合以及所有其他文档数据?
【发布时间】:2020-10-21 18:52:12
【问题描述】:

基本上我有一个文档,里面有一个 id、一个名称和一个集合。当我这样做时

const {name, id} = doc.data()

我得到了 ID 和名称,但是当我尝试获取名为 items 的集合时(通过像上面那样对其进行解构),它返回 undefined。我怎样才能得到这个集合?我是否必须对 items 集合进行另一个引用,然后 get() 还是有更有效的方法?

【问题讨论】:

    标签: javascript node.js firebase google-cloud-platform google-cloud-firestore


    【解决方案1】:

    Firestore 中的查询很浅。当您获得文档快照时,它不包含嵌套在该文档下的任何子集合。如果您想要来自子集合的数据,则必须通过构建路径来单独查询每个子集合:

    firestore
        .collection("top-level-collection")
        .doc("doc-id")
        .collection("nested-subcollection")
        .get()
    

    这将为您提供嵌套子集合中的所有文档。您必须知道它的名称才能查询它。

    【讨论】:

    • 好的!谢谢 :D 我暗地里希望有,但我想没有:) 谢谢你的回答!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-22
    • 2018-05-13
    • 1970-01-01
    • 2020-12-13
    • 1970-01-01
    • 2021-07-27
    相关资源
    最近更新 更多