【问题标题】:How to access subcollection in firestore after .where如何在 .where 之后访问 firestore 中的子集合
【发布时间】:2021-12-12 03:52:51
【问题描述】:

我有一个集合和一个名字数组,集合可以通过id直接查询

我想根据名称访问唯一的子集合,并且我想在之后返回子集合

查询的结构是这样的

firestore
.collection
.where("name", '==', inputName)
.collection('subCollection')
.get()

这个好像不行,有没有其他方法

【问题讨论】:

    标签: javascript database google-cloud-platform google-cloud-firestore


    【解决方案1】:

    Firestore 查询只能检查它们返回的文档中的数据。无法从子集合返回文档,并从父文档中筛选字段。

    常见的解决方案是将name 也添加到子集合中的每个文档(例如称为parentName 的字段),然后在所有名为subCollection 的集合中执行collection group query

    firestore
    .collectionGroup('subCollection')
    .where("parentName", '==', inputName)
    .get()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-11-11
      • 1970-01-01
      • 2020-09-20
      • 1970-01-01
      • 2022-07-31
      • 1970-01-01
      • 2022-01-05
      相关资源
      最近更新 更多