Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Firebase数据库触发器的云函数?_Firebase_Firebase Realtime Database_Google Cloud Functions - Fatal编程技术网

Firebase数据库触发器的云函数?

Firebase数据库触发器的云函数?,firebase,firebase-realtime-database,google-cloud-functions,Firebase,Firebase Realtime Database,Google Cloud Functions,知道我为什么不能使用childByAutoId吗 exports.addPersonalRecordHistory = functions.database.ref('/personalRecords/{userId}/current/{exerciseId}') .onWrite(event => { var path = 'personalRecords/' + event.params.userId + '/history/' + event.params.e

知道我为什么不能使用childByAutoId吗

exports.addPersonalRecordHistory = functions.database.ref('/personalRecords/{userId}/current/{exerciseId}')
    .onWrite(event => {

       var path = 'personalRecords/' + event.params.userId + '/history/' + event.params.exerciseId;
       var reference = admin.database().ref(path).childByAutoId();

       reference.set({
            username: "asd",
            email: "asd"
          });
  });
错误

childByAutoId()
用于iOS SDK。对于
admin.Database()
,请使用


它应该是这样工作的:

exports.addPersonalRecordHistory = functions.database.ref('/personalRecords/{userId}/current/{exerciseId}').onWrite(event => {
  var path = 'personalRecords/' + event.params.userId + '/history/' + event.params.exerciseId;
   return admin.database().ref(path).set({
    username: "asd",
    email: "asd"
  });
});

但这不是我想要的数据结构
var reference = admin.database().ref(path).push();
exports.addPersonalRecordHistory = functions.database.ref('/personalRecords/{userId}/current/{exerciseId}').onWrite(event => {
  var path = 'personalRecords/' + event.params.userId + '/history/' + event.params.exerciseId;
   return admin.database().ref(path).set({
    username: "asd",
    email: "asd"
  });
});