簡體   English   中英

Firebase Cloud Functions error_:未定義變量

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

我收到此錯誤:

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)

當我運行此功能(通過在文檔上寫入觸發):

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

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

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

錯誤是從這一行highscore_collection.doc(userid).set 我不明白這個錯誤,為什么沒有定義userid?

您從未定義變量userid 它不會自動創建,只是因為您在觸發器定義中將其聲明為通配符。 請閱讀有關在Firestore觸發器中使用通配符的文檔。 要獲取其匹配值,請將其從提供給函數的上下文中拉出:

const userid = context.params.userid;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM