部署 node.js 云函数时出错
Getting error while deploying node.js cloud function
我在我的应用程序中收到了 firebase 的实施通知。
这是我的node.js函数
'use strict'
const functions = require('firebase-functions');
const admin=require('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.sendNotificaiton=functions.database.ref('/Notifications/{userKey}/{notification_id}').
onWrite(event => {
const userKey = event.params.userKey;
const notification = event.params.notification;
console.log('The userKey is ', userKey);
});
我的 firebase 数据库结构是
函数错误是
请帮帮我。
提前致谢
更改您的代码
由此
exports.sendNotificaiton=functions.database.ref('/Notifications/{userKey}/{notification_id}').
onWrite(event => {
const userKey = event.params.userKey;
const notification = event.params.notification;
console.log('The userKey is ', userKey);
});
到此
exports.sendNotificaiton=functions.database.ref('/Notifications/{userKey}/{notification_id}').onWrite((change, context) => {
const userKey = context.params.userKey;
const notification = context.params.notification;
console.log('The userKey is ', userKey);
});
您正在为 onWrite()
使用旧的 event
触发器,现在您需要传递上下文和数据快照(更改)。
另外 onWrite
在写入事件触发数据库时具有 before
和 after
值
在此处查看文档:https://firebase.google.com/docs/functions/database-events?hl=en
有关通知,请参阅 github 上的通知示例:https://github.com/firebase/functions-samples/tree/Node-8/fcm-notifications
我在我的应用程序中收到了 firebase 的实施通知。 这是我的node.js函数
'use strict'
const functions = require('firebase-functions');
const admin=require('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.sendNotificaiton=functions.database.ref('/Notifications/{userKey}/{notification_id}').
onWrite(event => {
const userKey = event.params.userKey;
const notification = event.params.notification;
console.log('The userKey is ', userKey);
});
我的 firebase 数据库结构是
函数错误是
请帮帮我。 提前致谢
更改您的代码
由此
exports.sendNotificaiton=functions.database.ref('/Notifications/{userKey}/{notification_id}').
onWrite(event => {
const userKey = event.params.userKey;
const notification = event.params.notification;
console.log('The userKey is ', userKey);
});
到此
exports.sendNotificaiton=functions.database.ref('/Notifications/{userKey}/{notification_id}').onWrite((change, context) => {
const userKey = context.params.userKey;
const notification = context.params.notification;
console.log('The userKey is ', userKey);
});
您正在为 onWrite()
使用旧的 event
触发器,现在您需要传递上下文和数据快照(更改)。
另外 onWrite
在写入事件触发数据库时具有 before
和 after
值
在此处查看文档:https://firebase.google.com/docs/functions/database-events?hl=en
有关通知,请参阅 github 上的通知示例:https://github.com/firebase/functions-samples/tree/Node-8/fcm-notifications