Firestore获取根集合的所有文档和子集合 [英] Firestore get all docs and subcollections of root collection

查看:149
本文介绍了Firestore获取根集合的所有文档和子集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我有这种结构

    A (collection): { 
       a (doc): {
           name:'Tim',
           B (collection):{
               b (doc): {
                      color:'blue'
               }
             }
          }
    }

其中AB集合,而ab文档.
是否有一种方法可以通过一个查询获取根文档中包含的所有内容?
如果我这样查询

where A and B are collections while a and b are documents.
Is there a way to get everything contained in a root document with one query?
If I query like this

db.collection("A").doc("a").get()

我刚得到name:'Tim'字段.我想要的是也获取所有B的文件.
我基本上希望我的查询返回

I just gets name:'Tim' field. What I want is to also get all B's documents.
I basically wish my query returns

         {
           user:'Tim',
           B (collection):{
               b (doc): {
                      color:'blue'
               }
             }
          }

是可能还是真的需要针对每个集合进行多个查询:/?

Is it possibly or do I really need to make multiple queries one for each collection :/ ?

说我有一个非常深的嵌套的表示用户个人资料的集合树,由于每次加载用户个人资料时,我都有一个读取请求的乘数,因此我的成本会像地狱般上升.1 x N其中N是我的树的深度:/.

Say I have a really deep nested tree of collections representing the user profile, my costs will raise like hell since each time I load a user profile I have a multiplier of read requests 1 x N where N is the depth of my tree :/.

推荐答案

众所周知,默认情况下,Cloud Firestore中的查询是浅层的.虽然将来Google会考虑使用这种查询,但不支持这种查询.

As we know querying in Cloud Firestore is shallow by default. This type of query isn't supported, although it is something Google may consider in the future.

这篇关于Firestore获取根集合的所有文档和子集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆