Firebase云端功能 - 从数据库触发器获取父数据 [英] Cloud Functions for Firebase - get parent data from database trigger

查看:114
本文介绍了Firebase云端功能 - 从数据库触发器获取父数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种干净的方式直接引用数据库触发器上方节点的数据值?我知道我可以得到一个父母ref,然后我可以查询的价值,但如果有一个更简洁的方式做到这一点非常感谢。



清晰度,我想要使用一个对象内的子节点作为触发器,当它发生时直接获取父对象的值,以避免在对父对象进行其他更改时调用该函数,如下所示:

  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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆