Node.js中的Firestore onWrite回调具有未定义的上下文

时间:2018-04-18 10:30:08

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

我在onWrite集合中的文档上设置了一个简单的sandbox侦听器,只是为了测试侦听器API并看到我知道如何使用它。

显然我不这样做,因为我的index.js目录中有以下functions

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

exports.sandbox = functions.firestore.document('sandbox/{wildcard}')
    .onWrite((change, context) => {
        console.log("In")
        console.log("Before is " + change.before)
        console.log("Wildcard is " + context.params.wildcard)
        return null
    })

会产生以下输出(每当我在sandbox/yoohoo文档中添加/删除字段时):

In
Before is undefined
TypeError: Cannot read property 'params' of undefined

我做错了什么?

1 个答案:

答案 0 :(得分:3)

您似乎正在使用较旧版本的firebase-function,这就是未定义select [date], [desc], max(case when Seq = 1 then value end) val1, max(case when Seq = 2 then value end) val2, ... from (select [date], [desc], a.*, row_number() over (partition by [date], [desc] order by a.value) Seq from table t cross apply (values (val1), (val2).. (val5))a(value) ) tt group by [date], [desc]; params的原因,要更新您需要转到functions文件夹,并执行以下操作:

change.after

同时更新npm install firebase-functions@latest --save npm install firebase-admin@latest --save

firebase-tools

然后您将能够使用新版本,更多信息:

https://firebase.google.com/docs/functions/beta-v1-diff