如何从 Firestore 上的文档中获取所有集合 ID?

Mor*_*ton 5 javascript firebase react-native google-cloud-firestore

我从 React Native 项目连接数据库。

在我的 Firestore 数据库中Buildings/Taipei,我想获得所有的集合 ID,例如201 202 203 在此处输入图片说明

我尝试使用代码:

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}`);
    });
Run Code Online (Sandbox Code Playgroud)

我在doc. 在此处输入图片说明

任何帮助,将不胜感激。提前致谢。

Phi*_*lip 6

不幸的是,您目前无法在移动/网络客户端中执行此操作。

Cloud Firestore 服务器客户端库的 getCollections() 方法列出了文档引用的所有子集合。

使用移动/网络客户端库无法检索集合列表。在受信任的服务器环境中,您应该只在管理任务中查找集合名称。如果您发现移动/Web 客户端库中需要此功能,请考虑重构您的数据,以便子集合名称是可预测的。

来源:列出文档的子集