我正在使用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;
});
如何获取令牌节点并读取其值?
答案 0 :(得分:1)
我通过
解决了 var ref = event.after.ref.parent.parent.child('token');
ref.on('value', function(snapshot) {
console.log(`token value : ${snapshot.val()}`);
});