显示错误的firebase函数无法读取未定义的先前属性

时间:2018-08-10 09:04:59

标签: node.js firebase google-cloud-functions

我已经在我的应用程序中实现了Firebase函数,以前它运行良好,但现在显示错误无法读取未定义的属性“ previous” 功能错误日志 TypeError:无法读取未定义的属性“ previous” 在export.LoveNotification.functions.database.ref.onWrite(/user_code/index.js:223:16) 在cloudFunctionNewSignature(/user_code/node_modules/firebase-functions/lib/cloud-functions.js:109:23) 在cloudFunction(/user_code/node_modules/firebase-functions/lib/cloud-functions.js:139:20) 在/var/tmp/worker/worker.js:730:24 在process._tickDomainCallback(内部/进程/next_tick.js:135:7)

1 个答案:

答案 0 :(得分:1)

Cloud Functions触发器的签名已更改。您似乎正在使用Beta,但正在部署到最新版本。有关完整说明,请参见migration guide

从那里:

  

之前(<= v0.9.1)

true
     

现在(> = v1.0.0)

exports.dbWrite = functions.database.ref('/path').onWrite((event) => {
  const beforeData = event.data.previous.val(); // data before the write
  const afterData = event.data.val(); // data after the write
});

因此您的代码应如下所示:

exports.dbWrite = functions.database.ref('/path').onWrite((change, context) => {
  const beforeData = change.before.val(); // data before the write
  const afterData = change.after.val(); // data after the write
});