未定义ReferenceError {通配符} firebase云功能

时间:2019-03-16 03:32:07

标签: javascript firebase google-cloud-firestore

我创建了一个云函数“ createUser”,该函数将在每次在firestore中写入新用户时触发。数据写入成功,云功能也被触发。但这给我一个错误,未定义“ userId”通配符。我将esLint包含在我的项目中,但我认为这无关。

这是index.js代码

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

admin.initializeApp();

exports.createUser = functions.firestore
    .document('users/{userId}')
    .onCreate((snap, context) => {
    // Get an object representing the document
     // e.g. {'name': 'Marie', 'age': 66}
     const newValue = snap.data();

     // access a particular field as you would any JS property
     const name = newValue.name;

    // perform desired operations ...
});

Firestore结构

users
    vWil2QSrY0YBQH346pYlemQasdf
        email:
        name:

日志

ReferenceError: userId is not defined
at exports.createUser.functions.firestore.document.onCreate (/user_code/index.js:8:34)
at cloudFunctionNewSignature (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:105:23)
at cloudFunction (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:135:20)
at /var/tmp/worker/worker.js:827:24
at process._tickDomainCallback (internal/process/next_tick.js:135:7)

0 个答案:

没有答案