简体   繁体   English

是否可以从父集合(Firebase Cloud Firestore)访问子集合?

[英]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 现在我必须获取所有集合collection2collection4

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.

相关问题 是否可以获取Firebase Cloud Firestore数据库中可用的集合的文档ID? - Is it possible to get document id of collections available in Firebase Cloud Firestore database? Firestore 如何从 collections 中提取子集合 - Firestore how to extract sub collection from collections Firebase Firestore - 比较来自 2 collections 的数据 - Firebase Firestore - Compare data from 2 collections 如何从 Cloud Firestore 删除集合及其所有子集合和文档 - How to delete a collection with all its sub-collections and documents from Cloud Firestore 使用嵌套查询从 Firebase Firestore 中的子集合中获取数据 - Get data from sub-collections in Firebase Firestore using nested query Firebase中的Cloud Firestore-获取所有根级别集合 - Cloud Firestore in Firebase - Get all root level collections 如何从 firebase firestore 异步获取所有父 collections 的所有文档? - How can I get all the documents of a all parent collections asynchronously from firebase firestore? Cloud Firestore集合查询无法正常工作 - Cloud Firestore collections queries not working 是否可以通过 firebase CLI 创建 Firestore 集合/文档? - is it possible to create firestore collections/documents through firebase CLI? Shopify 从父集合的子 Collections 获取过滤器 - Shopify Get Filters from Sub Collections for Parent Collection
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM