使用来自Firebase实时触发器function的其他参考值

您好我开始添加一些后端逻辑到我的Android应用程序使用的Firebase函数我想使用一些不同的事件数据值的值

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); }); 

使用firebase-admin node_module

按照上面的我的评论,我做了testing的选项和想法,如果你从node_modules初始化Firebase-admin(确保它也包含在packages.json中),你可以从数据库中检索任何数据。

对于你的代码,我相信你只需要在index.js文件的开头添加index.js (包括所有其他的初始化):

 const admin = require('firebase-admin'); admin.initializeApp(functions.config().firebase); 

那么您可以稍后使用admin就像您通常使用firebase一样,如下所示:

 admin.database().ref('users/xxxx').once('value').then(function(snapshot){.... 

它完全适合我!