数据库触发器,从其他节点检索数据。 Firebase Cloud功能

时间:2017-11-13 04:22:15

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

我有一个在“用户”下更新“位置”时会触发的功能。我希望能够遍历所有“用户”并能够比较他们的“位置”。

现在当我在console.log event.data.val()时,我只获得了“位置”数据。 我如何升级并看到其他'用户'

exports.getNearest = functions.database.ref('/users/{pushId}/location').onWrite(event =>{

console.log(event.data.val());
return;
}
);

我的数据库结构如下:

https://gyazo.com/9d7a4ddba2cd311b21d78d7622b59c36

1 个答案:

答案 0 :(得分:0)

event.data.ref is a Reference where your function triggered. This means event.data.ref.parent is a reference to the parent node of that location. You can reach the root of your database using event.data.ref.root. If you need full read and write access regardless of the user who invoked the function, you may also want to use event.adminRef instead of ref.

相关问题