Firebase Cloud功能错误

时间:2017-11-18 09:10:27

标签: firebase firebase-realtime-database google-cloud-functions

这是我的Angular JS webapp的数据库JSON的一部分:

 users: {
   user uid (generated by push) : {
       deviceToken : "tokenID",
       name : "Display Name"
   },
   anotherUserID : {
       deviceToken : "tokenID",
       name : "Display Name"
   }

以下是我的云功能的索引JS:

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

// The Firebase Admin SDK to access the Firebase Realtime Database. 
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);

exports.update = functions.database.ref('/Player')
    .onWrite(event=>{
      console.log(event.data);
      var ref = admin.database().ref('/users/'+ user.uid+ '/week1');
      ref.set(10);
      return;

    });

我不断收到以下错误消息:

ReferenceError: user is not defined at exports.update.functions.database.ref.onWrite.event (/user_code/index.js:10:49)

我用ref = admin.database().ref('/users/'+ user.uid+ '/week1');替换了var var ref = admin.database().ref('/users/{user.uid}/week1');并收到以下错误消息:

Error: Firebase.child failed: First argument was an invalid path: "/users/{user.uid}/week1". Paths must be non-empty strings...

有没有办法访问数据库云功能中push()方法生成的用户uid?

0 个答案:

没有答案