firebase - Firebase 函数 onCreate 触发器错误:TypeError:无法读取未定义的属性“匹配”
问题描述
尝试使用为数据库触发的 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>
解决方案
您正在使用 Cloud Functions 的“旧”语法(Firebase SDK for Cloud Functions 的 1.0.0 版之前),onCreate((event) => {})
并且您项目中的 SDK 版本是 1.1.0 版。
您应该将语法更改为
.onCreate((snap, context) => {})
推荐阅读
- dictionary - 如何重用 SerializableDictionary
数据成员? - xslt - 如何检查XML中是否存在一个孩子
- spring-boot - 如何在 https 上运行 Spring Vault
- python - Python 在使用多处理时每 5 分钟运行一次部分代码
- python - discord.py bot 每次发送消息,并且仅在发送每个单词时完成
- json - bash - jq 在 json 上迭代,键和值中有空格
- javascript - 如何停止对每个输入事件的响应
- oracle - Oracle 低基数列索引排序性能
- excel - 用于查找特定范围内的项目并复制到另一张工作表的 VBA 代码
- javascript - Discord js中范围内的随机数生成器