如何从 Firestore 上的文档中获取所有集合 ID? [英] How to get all of the collection ids from document on Firestore?
问题描述
我从 React Native 项目连接数据库.
在我的 Firestore 数据库 Buildings/Taipei
中,我想获取所有集合 ID,例如 201
202
203代码>
我尝试使用代码:
const db = firebaseApp.firestore();db.collection('建筑物').doc('台北').得到().then(doc => {console.log('get doc is =>');控制台日志(文档);}).catch(error => {console.log(`错误是 ${error}`);});
我在 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屋!