[英]Is it possible to access a sub collections from parent collections (firebase cloud firestore)?
I have a collection like bellow: 我有一个像波纹管这样的收藏:
db.collection("col1/doc1/col2/doc2/col3/doc3/col4").get();
Now I have to get all collection collection2 and collection4 现在我必须获取所有集合collection2和collection4
With my current know knowledge I have to get them separately like bellow: 以我目前的知识,我必须像波纹管一样将它们分开:
db.collection("col1/doc1/col2").get();
and 和
db.collection("col1/doc1/col2/doc2/col3/doc3/col4").get();
My expectation is I want to call it at once with collection2 我的期望是我想立即使用 collection2 调用它
db.collection("col1/doc1/col2").get().then(snapshot=>{
//here something like snapshot.col3.col4
});
Is it possible like snapshot.col3.col4
? 是否有可能像
snapshot.col3.col4
一样?
Why I want like this ? 为什么我要这样?
Because I will not have to call it more than one time from server, may it increase performance and make it faster. 因为我不必在服务器上多次调用它,所以它可以提高性能并使其更快。
Is it possible like snapshot.col3.col4?
有可能像snapshot.col3.col4吗?
No, it's not. 不,这不对。 Queries in Firestore are shallow, which means that only get items from a collection that the query is run against.
Firestore中的查询很浅,这意味着只能从运行查询的集合中获取项目。 There is no way you can get documents from a top-level collection and a subcollections with different names in the same time.
您无法同时从顶级集合和具有不同名称的子集合中获取文档。 Firestore doesn't support queries across different collections with different names in one go.
Firestore不支持一次性使用不同名称的跨不同集合的查询。 A single query may only use properties of documents in a single collection.
单个查询只能使用单个集合中的文档属性。
A possible solution for your issue might be the use of Collection group queries , but as the doc states, all collections should have the same name. 对于您的问题的一种可能的解决方案可能是使用集合组查询 ,但是正如文档所述,所有集合都应使用相同的名称。
Another workaround might be, to create two separate queries and merge the result client side. 另一个解决方法可能是创建两个单独的查询并合并结果客户端。 For that I recommend you see my answer from the following post:
为此,我建议您从以下文章中查看答案:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.