Realtime Database triggers (pt.2) with Cloud Functions for Firebase - Firecasts

Firebase · 51K views · 2018 · 5:24

Open on YouTube

Cloud, DevOps & reliabilityWeb developmenttutorialdated

Why Stack Overflow recommends it

Stack Overflow users link it when answering questions about Cloud Functions database triggers, especially how to stop functions from recursively triggering themselves and how to read wildcard path parameters.

Recommended by 1 people across 1 different months, 2018 to 2023.

What it is

A short Firebase Firecasts episode in which Doug Stevenson explains how to write Realtime Database triggers with Cloud Functions for Firebase using the OnUpdate trigger for modified documents. It follows an earlier episode on OnCreate and covers wildcards, returning from functions, and avoiding infinite trigger loops.

What people said

Recommends Rohit Kharche · 2023-09 · Stack Overflow · on “How does one prevent Cloud Functions from recursively triggering themselves”

Refer to this video Realtime Database triggers (pt.2) with Cloud Functions for Firebase - Firecasts [this video] about how to terminate infinite loops in cloud functions triggers.

Cites Agung · 2018-08 · Stack Overflow · on “how do I get the dataID when using cloud firestore triggers function?”

I think I have misunderstanding about the wildcard after watching your video here [this video] , thanks Doug, I understand now.

Cites user10191119 · 2018-11 · Stack Overflow · on “Firebase - Cloud Functions - make queries on collection”

Strange because doug stevenson, google advocat also recommended to return null if a function should finish. And I guess null is assignable on any type. src: [this video]

Cites Doug Stevenson · 2020-03 · Stack Overflow · on “Is there a way to prevent infinite updates in Firestore?”

You will have to detect that case in your function code. There's no automatic detection. Specifically, your code will need to be able to recognize the situation where an update that triggers the function was a result of a prior update from the function itself. Sometimes this involves checking a flag in the document that indicates it was already processed, or finding some other way to see if the work was already done. If it was, the function should simply return without updating the document again. There is a video that discusses the same problem with Realtime Database. It's the exact same issue, just with a different database. [this video]

Cites HeroesVII · 2020-10 · Stack Overflow · on “firebase rules for Realtime Database”

I`m not sure if i understand your problem correctly: If you need to ad your new user's uid to Moder user's account in your db, then maybe the easier will be to use firebase functions, you can set function to listen at db path, and when new wuser will appear get data from him and write his uid in "UserUid#2 -> users -> UserUid#1:true". Some official video from firebase: [this video] From database you can write and read with admins priority so you don`t need to handle this in ruleset. If you really need to do this with ruleset, then maybe easier will be to rebase your json a bit, writing rules for nested data is harder. You can read about this here: [LINK]