Angular 正在尝试列出Firestore数据库的集合

Angular 正在尝试列出Firestore数据库的集合,angular,firebase,ionic-framework,google-cloud-firestore,Angular,Firebase,Ionic Framework,Google Cloud Firestore,我想列出Ionic4应用程序中Firestore数据库的集合,因此我使用了listCollection部分中的,因此我在代码中应用了示例代码: this.afs.firestore.listCollections().then(collections => { for (let collection of collections) { console.log(`Found collection with id: ${collection.id}`); } }); 这是我的

我想列出Ionic4应用程序中Firestore数据库的集合,因此我使用了listCollection部分中的,因此我在代码中应用了示例代码:

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,因为它位于联机文档中

事实上,正如Firestore JS SDK中详细介绍的那样,使用移动/web客户端库检索收藏列表是不可能的

这适用于Firestore数据库的根集合,也适用于Firestore文档的子集合

然而,正如您在问题中所提到的,它是有可能的。因此,您可以使用云函数来访问Firestore DB,并从前端调用此云函数

由于您将从应用程序调用此云函数,因此我们使用了一个

云函数代码 前端代码 要从Angular应用程序调用此可调用的云函数,只需遵循Angularfire for Cloud函数

import { Component } from '@angular/core';
import { AngularFireFunctions } from '@angular/fire/functions';

@Component({
  selector: 'app-root',
  template: `{ data$  | async }`
})
export class AppComponent {
  constructor(private fns: AngularFireFunctions) { 
    const callable = fns.httpsCallable('getCollections');
    this.data$ = callable({ .... });
  }
}


请注意,此方法的灵感来自以下内容,其中描述了如何使用JS SDK列出Cloud Firestore文档的所有子集合。(免责声明:我是作者)

您正在为
nodejs
使用文档。。。看吧,谢谢!我是否在我的Ionic应用程序中编写这些代码?前端代码是,但云功能代码应用于在您自己的Firebase项目中定义云功能:请参阅和
import { Component } from '@angular/core';
import { AngularFireFunctions } from '@angular/fire/functions';

@Component({
  selector: 'app-root',
  template: `{ data$  | async }`
})
export class AppComponent {
  constructor(private fns: AngularFireFunctions) { 
    const callable = fns.httpsCallable('getCollections');
    this.data$ = callable({ .... });
  }
}