gpt4 book ai didi

javascript - user_id 将在 firebase 云函数中未定义

转载 作者:行者123 更新时间:2023-11-30 20:29:59 25 4
gpt4 key购买 nike

我正在尝试在 node.js 中实现 firebase 云功能以部署到我的项目中。我想在函数内获取发送用户的用户 ID,但它即将变为“未定义”。

以前“事件”触发器用于导出函数,但在测试版 firestore 之后已迁移到 v1.0.0 以“更改、上下文”或“快照”。

我正在处理最新的查询,但无法获取 user_id。

exports.sendNotification = functions.firestore.document("Users/{user_id}/Notifications/{notification_id}").onWrite((change,context) => {

const user_id = context.user_id;
const notification_id = context.notification_id;

return console.log("user_id: " + user_id);

这会在控制台中返回“user_id: undefined”。请任何人告诉我正确的方法,以便我获得 user_id。提前致谢。

最佳答案

改变这个:

const user_id = context.user_id;
const notification_id = context.notification_id;

进入这个:

const user_id = context.params.user_id;
const notification_id = context.params.notification_id;

params

An object containing the values of the wildcards in the path parameter provided to the ref() method for a Realtime Database trigger.

关于javascript - user_id 将在 firebase 云函数中未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50460333/

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