firebase node js TypeError:无法读取属性' toId'未出口的出口

时间:2018-06-06 22:51:46

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

Hello to node Js

在我的firebase云功能日志中

它说它无法读取属性toId

我正在打印出console.log(事件),并且通配符toId会在我检查时显示用户的UID,那么我做错了什么?

这是我的代码:

  exports.sendMessageNotification = functions.database.ref('/user-messages-notification/{toId}/{fromId}/{message}')
  .onCreate((snap, context) => {

    console.log('This is the event:',event)

    var toId = context.params.toId
    var fromId = context.params.fromId

    console.log('User: ' + toId + ' recieved a message from  ' + fromId);

  var userRef = db.collection('Users').doc(toId);
        var getDoc = userRef.get()
            .then(doc => {
              if (!doc.exists) {
              return  console.log('No such document!');
              } else {

                  var User = doc.data();
              return  console.log('Document data:', doc.data());


              }
            })
            .catch(err => {
              //catch error does not need 'return console'
              console.log('Error getting document', err);
            });

  })

0 个答案:

没有答案