简体   繁体   中英

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.

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. I tried getAllCollections() its says the same. I tried to get the data from the doc but in only get the data and not the 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

The APIs you're trying to call are only available in the server-side SDKs for Firestore. There is no API to get a list of collections using the client SDKs for Firestore.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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