Firestore:获取在何处找到的文档的子集合 [英] Firestore: Get subcollection of document found with where

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

问题描述

我正在尝试将文档收集到一个子集合中,该子集合是使用.where函数找到的文档的一部分

I am trying to get the documents inside an subcollection which is part of an document found with the .where function

示例:

  • RootColl/
    • 文档A/
      • SubColl 1
        • Doc 1
        • Doc 2
        • Doc 3
        • RootColl/
          • Doc A/
            • SubColl 1
              • Doc 1
              • Doc 2
              • Doc 3
              • 文档
              • SubColl 1
                • Doc 1
                • Doc 2
                • Doc 3
                • SubColl 1
                  • Doc 1
                  • Doc 2
                  • Doc 3
                  • 文档

                  我想从文档中获取字段级别== 1的SubColl 1下的所有文档

                  I want to get all the documents under SubColl 1 from the doc with the field level == 1

                  我正在尝试这样做:

                  db.collection("RootColl").where("field", "==", "1").collection("SubColl 1").get()

                  但是这样做我得到了错误

                  But by doing that i get the error

                  Uncaught TypeError: db.collection(...).where(...).collection is not a function

                  按照弗兰克·范·普菲伦的建议,我遇到了同样的错误,收藏"不是一个函数

                  EDIT 1: By following Frank van Puffelen suggestion, i get the same error, "collection" is not a function

                  • Current Code
                  • Error

                  推荐答案

                  子集合位于特定文档下.您现在共享的查询指向到许多文档.您将需要执行查询以确定它指向的文档,然后遍历结果,并获取每个文档的子集合.

                  A sub-collection lives under a specific document. A query as you've shared now points to a number of documents. You'll need to execute the query to determine what documents it points to, then loop over the results, and get the sub-collection for each document.

                  在代码中:

                  var query = db.collection("RootColl").where("field", "==", "1");
                  query.get().then((querySnapshot) => {
                    querySnapshot.forEach((document) => {
                      document.ref.collection("SubColl 1").get().then((querySnapshot) => {
                        ...
                      });
                    });
                  });
                  

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

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