简体   繁体   English

Firebase Cloud Functions error_:未定义变量

[英]Firebase Cloud Functions error_: variable is not defined

I get this error: 我收到此错误:

ReferenceError: userid is not defined
  at exports.onUserNickUpdate.functions.firestore.document.onWrite (/srv/index.js:49:34)
    at cloudFunctionNewSignature (/srv/node_modules/firebase-functions/lib/cloud-functions.js:120:23)
    at /worker/worker.js:825:24
    at <anonymous>
    at process._tickDomainCallback (internal/process/next_tick.js:229:7)

When I run this function(gets triggered by write on document): 当我运行此功能(通过在文档上写入触发):

exports.onUserNickUpdate = functions.firestore.document('user/{userid}').onWrite((change,context) => {

    const changednick = change.after.data().nick

    return highscore_collection.doc(userid).set({
        nick: changednick
    })
})

Error is from this line highscore_collection.doc(userid).set . 错误是从这一行highscore_collection.doc(userid).set I don't understand this error, how come userid is not defined? 我不明白这个错误,为什么没有定义userid?

You never defined the variable userid . 您从未定义变量userid It doesn't get automatically created just because you declared it as a wildcard in your trigger definition. 它不会自动创建,只是因为您在触发器定义中将其声明为通配符。 Please read the documentation on using wildcards in a Firestore trigger . 请阅读有关在Firestore触发器中使用通配符的文档。 To get its matched value, pull it out of the context provided to the function: 要获取其匹配值,请将其从提供给函数的上下文中拉出:

const userid = context.params.userid;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM