Cloud Functions for Firebase - Getting Parent Data from a Database Trigger

Is there a clean, built-in way to directly reference the value of node data over a database trigger? I understand that I can get a parent reference that I could request for a value, but if there was a more concise way to do this, that would be a big thank you.

For clarity, I want to use the node child element inside the object as a trigger, and when it occurs, immediately get the value of the parent object to avoid calling the function when making other changes to the parent object like this:

const parentObject = {
 triggerValue: 'I want the function to be triggered only on writes to this path',
 parentValue: 'But I also want this value',
}

thank

+4
source share
2 answers

event.data.ref event.data.adminRef . Reference , - Firebase . , parent , . .

+1

, , .

, post post.body, :

exports.doStuff = functions.database
  .ref("/posts/{postId}/body")
  .onWrite(event => {
    return event.data.ref.parent.once("value").then(snap => {
      const post = snap.val();
      // do stuff with post here
    });
  });
+6

Source: https://habr.com/ru/post/1676376/


All Articles