如何从Firestore上的文档获取所有集合ID? [英] How to get all of the collection ids from document on Firestore?

查看:54
本文介绍了如何从Firestore上的文档获取所有集合ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

在我的Firestore数据库 Buildings/Taipei 中,我想获取所有的收藏ID,例如 201 202 203

我尝试使用代码:

  const db = firebaseApp.firestore();db.collection('Buildings').doc('Taipei').得到().then(doc => {console.log('get doc is =>');console.log(doc);}).catch(错误=> {console.log(`错误是$ {错误}`);}); 

doc 中看不到任何集合ID.

任何帮助将不胜感激.预先感谢.

解决方案

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

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

无法通过手机/网络检索收藏列表客户端库.您只应在以下位置查找集合名称:受信任服务器环境中的管理任务.如果你发现您需要在移动/网络客户端库中使用此功能,请考虑重组数据,以便子集合名称是可预测的.

来源:列出文档的子集合

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

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.

Any help would be appreciated. Thanks in advance.

解决方案

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

这篇关于如何从Firestore上的文档获取所有集合ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆