Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can retrieve {pushId} with firebase cloud functions?

I am learning firebase cloud functions. I have a function that looks like that:

exports.gameLoopBeing = functions.database.ref('/tables/{pushId}/gamestarted')
    .onWrite(event => {
    //I want to retrieve the pushID        
    console.log(event.data.pushID);

});

event.data.pushID clearly doesn't work. How can retrieve the pushID? I looked at the docs and couldn't find anything.

For those who don't know that pushId is. This function listens to every change done inside elements inside /table. For example:

  • in /table/1 the pushId is 1
  • in /table/2 the pushId is 2
  • in /table/N the pushID is N
like image 427
My Name Avatar asked May 27 '26 08:05

My Name


2 Answers

The wildcards in the ref path are provided in the event params object:

exports.gameLoopBeing = functions.database.ref('/tables/{pushId}/gamestarted')
    .onWrite(event => {
    //I want to retrieve the pushID        
    console.log(event.params.pushId);

});
like image 191
Bob Snyder Avatar answered May 30 '26 05:05

Bob Snyder


exports.gameLoopBeing = functions.database.ref('/tables/{pushId}/gamestarted')
     .onWrite((change, context) => {
     //I want to retrieve the pushID        
      console.log(context.params.pushId);
    });
like image 23
Anjusha T Shaju Avatar answered May 30 '26 07:05

Anjusha T Shaju



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!