Firebase云功能未执行

时间:2018-01-10 18:56:59

标签: node.js firebase google-cloud-functions

我试图创建一些firebase云功能,它似乎没有经历。我有点困惑,因为根据我读到的内容应该有效。

这是我写的或不执行的代码:

   //Custom master notification.
 exports.TrackMasterNotification = functions.database.ref('/'+DatabaseNode+'/GeneralMessage/Master')
    .onUpdate(event => {
        console.log("Processed new CUSTOM notification");
        //news has been created
        InitializeNotificationProcess();
        IdAndNotification.forEach(user => {
                //Should really find out which to send
               SendIOSNotification(user.NotificationId, event.data.val(), 'ping.aiff', 1, 3 );
               SendAndroidNotification(user.NotificationId, event.data.val(),"");
        });

    });

Firebase看起来像这样:

-Firebase project
 -Development
   - General Message
      - Master: "value"

修改

const DatabaseNode = "Development";

我已将参考号更改为

ref('/{DatabaseNode}/GeneralMessage/Master')

1 个答案:

答案 0 :(得分:1)

ref路径的语法看起来不对。它应该是:

/{databaseNode}/GeneralMessage/Master

此外,确认在您使用 onUpdate 时更新数据库的该分支内的元素时会触发它。

然后,您应该可以使用以下方法获取 databaseNode 值:

const node = event.params.databaseNode;