使用多个项目的 Firebase 云功能

Firebase Cloud function using multiple projects

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

您可以 initialize multiple Admin apps 在云函数中,如下所示:

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

const defaultFirestore = getFirestore();
const otherFirestore = getFirestore(otherApp);

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