您好,我正在尝试通过类似这样的函数访问我的Firebase实时数据库
exports.sendNotification = functions.database.ref('/requests/{id}/{formatted_address}').onCreate(event => {
const getSomethingPromise = admin.database().ref('/requests/{id}/{formatted_address}').once('value');
getSomethingPromise.then(results => {
const somethingSnapshot = results[0];
console.log(somethingSnapshot);
// Do something with the snapshot
})
const payLoad = {
notification:{
title: 'Message received',
body: 'You received a new message',
sound: "default"
}
};
const options = {
priority: "high",
timeToLive: 60*60*2
};
return admin.messaging().sendToTopic("/topics/notifications", payLoad, options);
});
我的最终目标是,每次添加新请求时,都会以/topics/notifications
的形式向用户发送一条带有formatted_address的通知,到目前为止,我在打印somethingSnapshot
时得到的都是undefined
。如何实现?
更新:现在,运行此功能时,我的firebase功能日志中出现错误TypeError: Cannot read property 'match' of undefined
。