【发布时间】:2018-09-13 18:56:15
【问题描述】:
我正在尝试使用我的移动应用程序执行一个简单的 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;
});
当新数据写入特定数据库表时触发,但出现此错误:
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)
【问题讨论】:
-
所有来到这里的人请注意:您可能使用的是某些教程的旧版本,该教程尚未更新为使用 Cloud Functions for Firebase API 1.0 版的 API。请通知教程的创建者他们的内容已过时。
标签: node.js firebase firebase-realtime-database firebase-cloud-messaging google-cloud-functions