Reputation: 486
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.
Upvotes: 2
Views: 1324
Reputation: 50840
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.
Upvotes: 6