简体   繁体   English

如何在 Firestore 的文档中获取 collections

[英]How to get the collections inside a document in firestore

I am trying to get all the collections inside the document, but i am getting errors.我正在尝试获取文档中的所有 collections,但出现错误。

I am doing this:我正在这样做:

this.db = firebase.firestore();

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

And it says listCollections() is not a function.它说 listCollections() 不是 function。 I tried getAllCollections() its says the same.我试过 getAllCollections() 它说的一样。 I tried to get the data from the doc but in only get the data and not the collections.我试图从文档中获取数据,但只获取数据而不是 collections。

I dont know what else to do.What i am doing wrong?我不知道还能做什么。我做错了什么?

My firestore:我的火库:

Collection --- > "RestaurantMenus" ----> doc: this.restaurant.key ----> collection that i want to get集合--->“RestaurantMenus”----> doc: this.restaurant.key ----> 我想要的集合

The APIs you're trying to call are only available in the server-side SDKs for Firestore.您尝试调用的 API 仅在 Firestore 的服务器端 SDK 中可用。 There is no API to get a list of collections using the client SDKs for Firestore.没有 API 可以使用 Firestore 的客户端SDK 获取 collections 的列表。

For this reason you'll typically want to use fixed names (like your "RestaurantMenus") for your collection ID, and only use generated IDs for documents.出于这个原因,您通常希望使用固定名称(如“RestaurantMenus”)作为您的集合 ID,并且只将生成的 ID 用于文档。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM