Node.js 实时数据库触发通知

Node.js 实时数据库触发通知,node.js,firebase,firebase-realtime-database,firebase-cloud-messaging,google-cloud-functions,Node.js,Firebase,Firebase Realtime Database,Firebase Cloud Messaging,Google Cloud Functions,下面是实时数据库更改的触发器 const functions = require('firebase-functions'); const admin = require('firebase-admin'); admin.initializeApp(functions.config().firebase); exports.notification = functions.database.ref('/chatroom-98902/').onWrite(event => { va

下面是实时数据库更改的触发器

const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);

exports.notification = functions.database.ref('/chatroom-98902/').onWrite(event => {

   var topic = 'Warning';

   var message ={
       data :{
           title:"Warning",
           body:"123"
        },
       topic: topic
    };
    admin.messaging().send(message)
    .then(function(response) {
        console.log("Successfully sent message:",response);
    })
    .catch(function(error) {
        console.log("Error sending message:",error);
    });

});
但当我在手机上测试时,它不会在数据库发生变化时触发,
我的代码有什么问题吗?

请注意,云函数最近已更新为V1.0,但语法有一些更改,请参阅:

如果使用此新版本,则必须从以下位置更改代码:

exports.notification = functions.database.ref('/chatroom-98902/').onWrite(event => {


要检查您使用的是哪个版本,请查看您的
package.json
文件(
dependencies
node)

我按照您的建议更改了代码,但当我更改实时数据库时,它仍然无法收到通知。这是两个错误“未配置计费帐户。外部网络无法访问,配额受到严重限制。配置计费帐户以删除这些限制,“函数返回未定义、预期承诺或值”。这会是问题吗?非常感谢您的回答。
exports.notification = functions.database.ref('/chatroom-98902/').onWrite((change, context) => {