【发布时间】:2018-05-04 07:14:26
【问题描述】:
好的,我查看了类似的问题,例如 Firebase function onWrite not being called,并认为获得参考是我的错,但我不知道我的 Firebase 函数发生了什么。
我只是想在对数据库进行写入时获取一个写入我的数据库的函数。我完全按照 firebase 教程进行操作:
const functions = require('firebase-functions');
// The Firebase Admin SDK to access the Firebase Realtime Database.
//https://firebase.google.com/docs/functions/database-events
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
// const gl = require('getlocation');
exports.helloWorld = functions.https.onRequest((request, response) => {
response.send("Hello from Firebase!");
});
exports.enterLocation = functions.database.ref('/Users/{name}') //brackets is client param
.onWrite(event => {
// Grab the current value of what was written to the Realtime Database.
// const original = event.data.val();
console.log('SKYLAR HERE:', event.params.name);
// You must return a Promise when performing asynchronous tasks inside a Functions such as
return firebase.database().ref('/Users/{name}').set({ location: 'test loc' });
});
该函数正在运行,但在我的日志中我收到一个非常无用的错误,它正在获取 {name} 参数,并且数据肯定已写入我的数据库,但是我的 SERVER 代码没有写入:
我明白了——
ReferenceError:firebase 未定义在 export.enterLocation.functions.database.ref
按照定义,这是没有意义的。我只想在我创建的用户下添加一个额外的孩子,就像我已经使用“密码”一样
我做错了什么?
【问题讨论】:
标签: javascript firebase firebase-realtime-database google-cloud-functions