繁体   English   中英

如何在.where之后访问firestore中的子集合

[英]How to access subcollection in firestore after .where

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

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

查询的结构是这样的

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

这似乎不起作用,有没有其他方法

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

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

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

暂无
暂无

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

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