[英]How to get all documents in a firestore subcollection based on the parent´s doc values?
我有 Firebase Firestore 中子集合的路径: Team/TeamName/Meetings/First/Data 。 我想知道是否有任何方法可以根据第一个文档(父文档)中的值(字段)获取数据子集中的文档。
我试过这个:
db.collection("Team")
.doc("TeamName")
.collection('Meetings').where('0', '==', "some data")
.where('3', '==', "doc data")
.where('4', '==', "something in textfiel").collection("Data")
但这种方法行不通。
Firestore 查询只能考虑查询的集合或子集合中的文档字段。 没有将跨多个集合的文档之间的数据组合在一起的“连接”。
您尝试执行的操作至少需要两个查询。 首先,查询从“团队”获取父文档:
db
.collection("Team")
.where(/* your conditions on Teams documents here */)
.get()
然后,对于每个匹配的父文档,您将需要对每个子集合中的文档进行更多查询。
db
.collection("Team")
.doc(matchingDocId)
.collection("Meetings")
.where(/* Any filters on documents in Meetings */)
.get()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.