Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase Cloud Function onWrite child value

I am using Firebase Cloud Function to send FCM upon Real-Time Database Triggered event. How can I get the value of a child ('uid') inside of {followerUid}?

exports.sendFollowerNotification = functions.database.ref('/followers/{followedUid}/{followerUid}').onWrite(event => {
  const followerUid = event.params.followerUid;
  const followedUid = event.params.followedUid;
like image 257
Zhen Jing Heng Avatar asked Jul 22 '26 05:07

Zhen Jing Heng


2 Answers

I know exactly what you are looking for...

var uid = event.data.val();
var uid1 = String(uid);

add this uid1 to title or body

const payload = {
      notification: {
        title: paypes
        body:  uid1
      }
    };
like image 167
bhargav N Reddy Avatar answered Jul 24 '26 20:07

bhargav N Reddy


I'm not sure I understand what you're trying to do but will take a stab.

If you are looking to access the data of uid inside the node that triggered the function:

var uid = event.data.child("uid").val;

Have a look at the documentation on handling event data.

like image 31
Frank van Puffelen Avatar answered Jul 24 '26 20:07

Frank van Puffelen



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!