Firebase函数-获取当前DataSnapshot的同级 [英] Firebase functions - get sibling of current DataSnapshot
本文介绍了Firebase函数-获取当前DataSnapshot的同级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的数据库结构如下
My database is structured as follows
我正在使用Firebase云功能中的onWrite(snapshot, context)
来监听活动节点.我想根据活动量的变化获取令牌节点的值.
I am listening to actives node by using onWrite(snapshot, context)
in firebase cloud functions. I want to get the value of token node based on change in actives.
我的触发功能如下.
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;
});
如何获取令牌节点并读取其值?
How do I get token node and read its value?
推荐答案
我通过
var ref = event.after.ref.parent.parent.child('token');
ref.on('value', function(snapshot) {
console.log(`token value : ${snapshot.val()}`);
});
这篇关于Firebase函数-获取当前DataSnapshot的同级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文