0

Based on Firebase documentation, one can create a cloud function to trigger when documents are added/updated/deleted on Firebase database through:

functions.database.ref('/messages/{pushId}/original').onUpdate();

However, using the Node.js admin SDK, when I call the following:

admin.database().ref("/messages/{pushId}/original").onUpdate();

It returns the error:

TypeError: admin.database(...).ref(...).onUpdate is not a function

What else we should do to get access to Firebase Realtime Database Triggers on Cloud Run or Kubernetes?

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
1man
  • 5,216
  • 7
  • 42
  • 56

1 Answers1

1

firebaser here

The onUpdate method only exists in the firebase-functions SDK and in the Cloud Functions equivalent on GCP. It does not exist in the Firebase Admin SDK, which is why you get an error when you try to use it there.

While it may be possible to receive Realtime Database events on Cloud Run (I haven't tried this myself), you will have to follow the process outlined for Eventarc on Cloud Run and then wire up the Realtime Database events as documented there.

Update: as a team mate pointed out, the Realtime Database triggers you can receive through Eventarc today are for administrative events, like creation and deletion of database instances. Triggers for data-level events are in the works, but not available yet (nor any timelines on when they will be).

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • Thank you, Frank, for your quick reply. The only reason we need to use this in our project, a collaborative learning game app, is https://firebase.google.com/docs/firestore/solutions/presence Cloud Functions are slow to fire, which gets annoying in our web-based game app. That's why we'd like to implement it in Cloud Run. Is there any more efficient way to manage user presence in Firestore? – 1man Sep 24 '21 at 18:56
  • 1
    Firestore's protocol between client and server is connectionless, so it doesn't really have any way to handle presence. A common alternative would be to periodically send a timestamp from the client to the server, and then use that to determine whether you consider each client to still be alive. This is typically called a heartbeat, so you might want to search for that term. – Frank van Puffelen Sep 24 '21 at 19:35