Firebase函数,admin.database().ref(...).get()不是函数 [英] Firebase Functions, admin.database().ref(...).get() is not a function
问题描述
我正在开发一个Android应用程序,并且正在使用firebase作为它的后端.我正在尝试使通知系统能够正常工作,该系统依赖于侦听数据库中的更改.虽然出现问题,但出现以下错误.想知道是否有人能够提供帮助,是否可以提供任何额外的代码.
I am working on an Android Application and am using firebase as the back end for it. I am trying to get a notification system working that relies on listening to changes in the database. Having problems though as I am getting the following error. Wondered if anyone would be able to help, any extra code can be supplied.
Firebase功能
'use-strict'
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.sendNotification = functions.database.ref("Notifications/{user_id}/{notification_id}").onWrite((data, context)=>{
const user_id = context.params.user_id;
const notification_id = context.params.notification_id;
console.log("User ID : " + user_id + " | Notification ID : " + notification_id);
return admin.database().ref("Notifications/" + user_id + "/" + notification_id).get().then(queryResult => {
const job_id = queryResult.data().Job;
const from_data = admin.database().ref("Jobs/" + job_id).get();
const to_data = admin.database().ref("Users/" + user_id).get();
return Promise.all([from_data, to_data]).then(result => {
const job_name = result[0].data().advertName;
const to_name = result[1].data().fullName;
console.log("JOB : " + job_name + " | TO : " + to_name);
return undefined;
});
});
});
功能错误
推荐答案
似乎您正在混淆Realtime Database和Firestore API.Firebase实时数据库API不提供get()方法来获取数据.为此,您可以在 once()上使用参考对象.
It looks like you're mixing up the Realtime Database and Firestore APIs. Firebase Realtime Database APIs doens't provide a get() method to fetch data. For that, you use once() on a Reference object.
这篇关于Firebase函数,admin.database().ref(...).get()不是函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!