相关疑难解决方法(0)

Firebase函数:无法读取未定义的属性"user_id"

我试图用我的移动应用程序做一个简单的hello world firebase功能,我想记录用户ID,以便我可以看到该功能确实有效.这是我目前的javascript代码:

const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);

exports.sendNotification = functions.database.ref('/notifications/{user_id}').onWrite((event) => {

  console.log('Testing stuff', event.params.user_id);

  return;
});
Run Code Online (Sandbox Code Playgroud)

当新数据写入特定数据库表时会触发,但会显示以下错误:

TypeError: Cannot read property 'user_id' of undefined
    at exports.sendNotification.functions.database.ref.onWrite (/user_code/index.js:8:44)
    at Object.<anonymous> (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:112:27)
    at next (native)
    at /user_code/node_modules/firebase-functions/lib/cloud-functions.js:28:71
    at __awaiter (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:24:12)
    at cloudFunction (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:82:36)
    at /var/tmp/worker/worker.js:700:26
    at process._tickDomainCallback (internal/process/next_tick.js:135:7)
Run Code Online (Sandbox Code Playgroud)

通知数据库如下所示: 在此输入图像描述

node.js firebase firebase-realtime-database google-cloud-functions firebase-cloud-messaging

5
推荐指数
1
解决办法
6125
查看次数