Ocelyn
Ocelyn

Reputation: 53

Firebase Function how to call a region real time database

I am struggling with one issue:

I have a cloud function that trigger on the realtime database

  .ref("/games/...")
  .onWrite(async (change) => { 

It's working pretty well on the default realtime database (asia) but not on the europe-west1

So I tried functions.regions('europe-west1').database but no success, I couldn't find any help online.

Thanks for your help

Upvotes: 2

Views: 351

Answers (1)

Dharmaraj
Dharmaraj

Reputation: 50830

The .region() specifies where the Cloud function will run and has nothing to with database. You are probably looking for instance():

instance() registers a function that triggers on events from a specific Firebase Realtime Database instance.

By default functions.database.ref used without instance watches the default instance for events and that's why the trigger works for your default DB in Asia.

firebase.database.instance('my-app-db-2').ref('/foo/bar').onWrite(async (change) => {})

Checkout 'specify the instance and path' section in the documentation.

Upvotes: 2

Related Questions