使用多个项目的 Firebase Cloud 功能

Dam*_*ina 2 google-cloud-platform google-cloud-functions google-cloud-firestore

是否可以使用单个云函数查询来自 2 个不同 Firebase 项目的数据。我想将“my-app”项目的 Firestore 中执行的更改镜像到“my-app-backup”项目的 Firestore。

Dha*_*raj 6

您可以在云功能中初始化多个管理应用程序,如下所示:

// Initialize the default app
initializeApp(defaultAppConfig);
const otherApp = initializeApp(otherAppConfig, 'other');

const defaultFirestore = getFirestore();
const otherFirestore = getFirestore(otherApp);
Run Code Online (Sandbox Code Playgroud)

在这里,您可以使用defaultFirestore从第一个 Firestore 项目读取,然后otherFirestore在另一个项目中写入。