Firebase函数-获取当前DataSnapshot的同级

时间:2018-09-07 10:37:51

标签: android firebase firebase-realtime-database google-cloud-functions

我的数据库结构如下 enter image description here

我正在使用Firebase云功能中的onWrite(snapshot, context)来监听活动节点。我想根据活动的变化获取令牌节点的值。

我的触发功能如下。

exports.sendNotification = functions.database.ref('root/users/{userid}/actives/{pushId}')
.onWrite((event, context) => {

var token; 

var active_userid = context.params.pushId;
   if(event.after._data != null){ 
        console.log(event.after.ref.parent.parent);

   }else{

       console.log('data is null')

   } 
return 0;

});

如何获取令牌节点并读取其值?

1 个答案:

答案 0 :(得分:1)

我通过

解决了
 var ref = event.after.ref.parent.parent.child('token');

          ref.on('value', function(snapshot) {
                        console.log(`token value : ${snapshot.val()}`);
                        });
相关问题