【问题标题】:How to get the collections inside a document in firestore如何在firestore的文档中获取集合
【发布时间】:2020-12-21 14:18:08
【问题描述】:

我正在尝试获取文档中的所有集合,但出现错误。

我正在这样做:

this.db = firebase.firestore();

this.db.collection("RestaurantMenus").doc(this.restaurant.key).listCollections().then((querySnapshot) => {
      querySnapshot.forEach((collection) => {
        console.log("collection: " + collection.id);
      });

它说 listCollections() 不是一个函数。我试过 getAllCollections() 它说的一样。我试图从文档中获取数据,但只获取数据而不是集合。

我不知道还能做什么。我做错了什么?

我的火库:

Collection ---> "RestaurantMenus" ----> doc: this.restaurant.key ----> 我想要获取的集合

【问题讨论】:

    标签: javascript angular firebase google-cloud-firestore


    【解决方案1】:

    您尝试调用的 API 仅在 Firestore 的服务器端 SDK 中可用。没有 API 可以使用 Firestore 的 client SDK 获取集合列表。

    因此,您通常希望为集合 ID 使用固定名称(如“RestaurantMenus”),并且只对文档使用生成的 ID。

    【讨论】:

      猜你喜欢
      • 2018-04-09
      • 2018-04-09
      • 2019-09-24
      • 2021-08-23
      • 2018-03-29
      • 1970-01-01
      • 1970-01-01
      • 2021-11-04
      • 1970-01-01
      相关资源
      最近更新 更多