我想列出Ionic4应用程序中Firestore数据库的集合,所以我在listCollection部分使用doc,所以我在代码中应用了示例代码:
this.afs.firestore.listCollections().then(collections => {
for (let collection of collections) {
console.log(`Found collection with id: ${collection.id}`);
}
});
下面是我构造函数:
constructor(private router: Router,
private afs: AngularFirestore,
private fireauth: AngularFireAuth) { }
我得到这个错误:错误TS2339:类型“Firestore”上不存在属性“listCollections”。
我无法使用属性listCollections,因为它在在线文档中...
1条答案
按热度按时间envsm3lx1#
Actually, as detailed in the Firestore JS SDK documentation , retrieving a list of collections IS NOT possible with the mobile/web client libraries.
This is true for the roots collections of your Firestore database but also for the sub-collections of a Firestore document.
However, as you have mentioned in your question, it IS possible with the Cloud Firestore Node.js Client API . Therefore you can use a Cloud Function to list the collections of your Firestore DB and call this Cloud Function from your front-end.
Since you will call this Cloud Function from your app we use a Callable Cloud Function .
Cloud Function Code
Front-end Code
To call this callable Cloud Function from your Angular app, just follow the Angularfire documentation for Cloud Functions.
Note that this approach is inspired from the following article , which describes how to list all subcollections of a Cloud Firestore document with the JS SDK. (Disclaimer: I'm the author)