国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

試著列出 Firestore 資料庫的集合
P粉546179835
P粉546179835 2023-08-24 23:19:00
0
1
757
<p>我想列出 Ionic4 應(yīng)用程式內(nèi)的 Firestore 資料庫集合,因此我使用 listCollection 部分中的文檔,因此我在程式碼中應(yīng)用了範(fàn)例程式碼:</p> <pre class="brush:php;toolbar:false;">this.afs.firestore.listCollections().then(collections => { for (let collection of collections) { console.log(`Found collection with id: ${collection.id}`); } });</pre> <p>這是我的建構(gòu)子:</p> <pre class="brush:php;toolbar:false;">constructor(private router: Router, private afs: AngularFirestore, private fireauth: AngularFireAuth) { }</pre> <p>我收到此錯(cuò)誤:錯(cuò)誤 TS2339:「Firestore」類型上不存在屬性「listCollections」。 </p> <p>我無法使用屬性 listCollections,因?yàn)樗混毒€上文件... </p>
P粉546179835
P粉546179835

全部回覆(1)
P粉265724930

實(shí)際上,如 Firestore JS SDK 文件 中所述,使用行動(dòng)/網(wǎng)路用戶端程式庫無法檢索集合清單。

這不僅適用於 Firestore 資料庫的根集合,也適用於 Firestore 文件的子集合。

但是,如您在問題中提到的,可以使用 Cloud Firestore Node.js 用戶端 API。因此,您可以使用 Cloud Function 來列出 Firestore 資料庫的集合並從前端呼叫此雲(yún)端函數(shù)。

由於您將從應(yīng)用程式中呼叫此雲(yún)端函數(shù),因此我們使用可呼叫雲(yún)函數(shù) .

雲(yún)端函數(shù)程式碼

const functions = require('firebase-functions');
const admin = require('firebase-admin');

admin.initializeApp();

exports.getCollections = functions.https.onCall(async (data, context) => {

    const collections = await admin.firestore().listCollections();
    const collectionIds = collections.map(col => col.id);

    return { collections: collectionIds };

});

前端程式碼

要從 Angular 應(yīng)用程式呼叫此可呼叫雲(yún)函數(shù),只需遵循 Angularfire 雲(yún)函數(shù)文件。

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({ .... });
  }
}

請(qǐng)注意,此方法的靈感來自以下文章,介紹如何使用 JS SDK 列出 Cloud Firestore 文件的所有子集合。 (免責(zé)聲明:我是作者)

最新下載
更多>
網(wǎng)站特效
網(wǎng)站源碼
網(wǎng)站素材
前端模板