How to get all of the collection ids from document on Firestore?

Viewed 11002

I connect the database from React Native project.

In my Firestore database Buildings/Taipei, i want to get all of the collection ids like 201 202 203 enter image description here

I try to use the code:

const db = firebaseApp.firestore();

    db.collection('Buildings').doc('Taipei')
    .get()
    .then(doc => {
      console.log('get doc is =>');
      console.log(doc);
    }).catch(error => {
      console.log(`error is ${error}`);
    });

I can't see any collection id in the doc. enter image description here

Any help would be appreciated. Thanks in advance.

1 Answers

Unfortunately what you want to do is not currently possible in the mobile/web client.

The getCollections() method of the Cloud Firestore server client libraries lists all subcollections of a document reference.

Retrieving a list of collections is not possible with the mobile/web client libraries. You should only look up collection names as part of administrative tasks in trusted server environments. If you find that you need this capability in the mobile/web client libraries, consider restructuring your data so that subcollection names are predictable.

Source: List Subcollections of Document

Related