Firebase云端功能 - 从数据库触发器获取父数据 [英] Cloud Functions for Firebase - get parent data from database trigger
问题描述
清晰度,我想要使用一个对象内的子节点作为触发器,当它发生时直接获取父对象的值,以避免在对父对象进行其他更改时调用该函数,如下所示:
const parentObject = {
triggerValue:'我想只在写入这个路径时触发函数'
parentValue:'但是我也想要这个值',
}
谢谢
您可以使用 event.data.ref
和 event.data.adminRef
来导航数据库。他们是参考对象,其工作原理与您的工作方式完全相同在客户端使用Firebase构建Web应用程序。因此,如果使用家长属性向上导航一个级别可以正常工作,然后使用它。没有额外的特殊语法。
Is there a clean built in way of directly referencing the data value of the node above the database trigger? I understand I can get a parent ref which I could then query for the value, but if there was a more concise way of doing this that would be great thanks.
For clarity, I want to use a child node within an object as a trigger, and when it occurs get the value of the parent object directly, to avoid the function being invoked when other changes are made to the parent object like so:
const parentObject = {
triggerValue: 'I want the function to be triggered only on writes to this path',
parentValue: 'But I also want this value',
}
Thanks
You can use event.data.ref
and event.data.adminRef
to navigate the database. They are Reference objects and work exactly like they would if you were building a web app with Firebase on the client side. So, if using the parent property to navigate up a level works fine for you, then just use that. There's no additional special syntax.
这篇关于Firebase云端功能 - 从数据库触发器获取父数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!