【发布时间】:2019-02-02 18:03:48
【问题描述】:
尝试使用为数据库触发的 OnCreate 部署函数,但它一直向我返回此错误。这是简单的代码和错误响应:
只是无法弄清楚为什么匹配未定义错误?
模块版本:
nodejs: Version 8.11.3
Function : deployed with node 8 runtime version.
"firebase": "^5.3.0"
"firebase-admin": "^5.12.1"
"firebase-functions": "^1.1.0"
"typescript": "^2.5.3"
代码:
import functions = require('firebase-functions');
import admin = require('firebase-admin');
exports.functionName = functions.database.ref('/user/{uid}/email').onCreate((snap, context) => {
console.log(snap.val());
});
问题更新:这是最新和最新的代码。我正在尝试获取新添加的对象的详细信息。
Firebase 数据库中向用户添加了一个新元素时出错:
TypeError: Cannot read property 'match' of undefined
at resourceToInstanceAndPath (/srv/node_modules/firebase-functions/lib/providers/database.js:154:26)
at dataConstructor (/srv/node_modules/firebase-functions/lib/providers/database.js:122:38)
at Object.<anonymous> (/srv/node_modules/firebase-functions/lib/cloud-functions.js:89:32)
at Generator.next (<anonymous>)
at /srv/node_modules/firebase-functions/lib/cloud-functions.js:28:71
at new Promise (<anonymous>)
at __awaiter (/srv/node_modules/firebase-functions/lib/cloud-functions.js:24:12)
at cloudFunction (/srv/node_modules/firebase-functions/lib/cloud-functions.js:82:36)
at /worker/worker.js:728:24
at <anonymous>
【问题讨论】:
-
以下应该可以,看我的回答:
exports.dbCreate = functions.database.ref('/user/{uid}/email').onCreate((snap, context) => { const createdData = snap.val(); console.log(createdData); });
标签: firebase firebase-realtime-database google-cloud-functions