Firebase Cloud function using multiple projects

Viewed 261

Is it possible to have a single cloud function query data from 2 different Firebase projects. I'd want to mirror changes performed in "my-app" project's Firestore to "my-app-backup" project's Firestore.

1 Answers

You can initialize multiple Admin apps in a Cloud function as shown below:

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

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

Here you can use defaultFirestore to read from first Firestore project and then otherFirestore to write in another.

Related