以编程方式查找Firestore Doc的所有子集合
问题描述:
有什么方法可以以编程方式访问文档中的子集合而无需明确知道其名称?我本质上是在寻找类似于firestore().getCollections()的函数,但要的是文档而不是数据库的根.
Is there any way to programmatically access the subcollections in a document without explicitly knowing their name? I'm essentially looking for a function similar to firestore().getCollections() but for a document rather than the root of the database.
db
.collection("collection")
.doc("document")
.get()
.then(doc => {
if (doc.exists) {
doc.getCollections().then(collections => {
//do stuff
});
}
})
//...
很显然docSnapshots没有此功能,但是还有其他方法可以实现此功能吗?还是您必须提前知道子集合的名称?
Obviously docSnapshots don't have this function, but is there any other way to achieve this? Or do you have to know the subcollection's name ahead of time?
答
我是个白痴.
db
.collection("collection")
.doc("document")
.getCollections()
.then(collections => {
//do stuff
});