gpt4 book ai didi

firebase - Cloud Functions for Firebase - 从数据库触发器获取父数据

转载 作者:行者123 更新时间:2023-12-02 19:07:49 24 4
gpt4 key购买 nike

是否有一种干净的内置方法可以直接引用数据库触发器上方节点的数据值?我知道我可以获得一个父引用,然后我可以查询该值,但如果有更简洁的方法来执行此操作,那就太好了。

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

const parentObject = {
triggerValue: 'I want the function to be triggered only on writes to this path',
parentValue: 'But I also want this value',
}

谢谢

最佳答案

我已经在 google 上搜索了这个答案六次,并且一直不得不重新实现该解决方案。

以下是如何从已更改的子属性 post.body 获取父数据 post:

exports.doStuff = functions.database
.ref("/posts/{postId}/body")
.onWrite(event => {
return event.data.ref.parent.once("value").then(snap => {
const post = snap.val();
// do stuff with post here
});
});

关于firebase - Cloud Functions for Firebase - 从数据库触发器获取父数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43784744/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com