嗨我开始使用firebase函数向我的android应用程序添加一些后端逻辑我想使用一些不同于事件数据值的值
exports.makeUppercase = functions.database.ref('path')
.onWrite(event => {
const original = event.data.val();
//I want to use value like this.
const other_val= root.database.ref('path').val();
console.log('email', "firms", original);
const uppercase = original.toUpperCase();
return event.data.ref.parent.child('uppercase').set(uppercase);
});
我想使用 other_valwith 事件数据,但到目前为止我只使用事件数据引用,但我可以使用更多父或子在数据库 event.data.ref 中上升或下降。我该如何解决?
编辑:感谢@davidtaubmann 的回答,我尝试学习正确的方法。
exports.makeUppercase = functions.database.ref('/nonVerifiedUsers/{email}')
.onWrite(event => {
var changed= "";
// You can use ref parameter like this
var param=event.params.email;
admin.database().ref('/uppercase').once('value').then(function(snap){
changed=snap.val();
}).then(function(){
/*if you want to use changed value wait until it return and return where
you want using admin.database.ref and use event parameter in reference like
this*/
return admin.database.ref('/path/').child(param).set(changed);
/*You can return regular event data but make sure you didn't write under
same reference server count this again as event and loop until reach 32 th child(maxiumum child nodes)*/
return event.data.ref.parent.child('uppercase').set(changed);
});
//In addition you can return multiple times in one function:
return event.data.ref.parent.child('dif').set(changed);
});