【问题标题】:How to trigger Cloud Function only when child is added to the database?仅在将子项添加到数据库时如何触发云功能?
【发布时间】:2017-08-29 23:12:59
【问题描述】:

如何修改下面的代码,使函数仅在添加孩子时触发?目前,每次指定引用发生变化时都会触发该函数...

const functions = require('firebase-functions');

const admin = require('firebase-admin');

admin.initializeApp(functions.config().firebase);



exports.myFunction = functions.database.ref('/messaging/{pushId}')

.onWrite(event => {

//child is added. Do something!

});

【问题讨论】:

    标签: javascript firebase firebase-realtime-database google-cloud-functions


    【解决方案1】:

    使用onCreate() 处理程序而不是onWrite()

    exports.myFunction = functions.database.ref('/messaging/{pushId}')
    
    .onCreate(event => {
    
    //child is added. Do something!
    
    });
    

    【讨论】:

      猜你喜欢
      • 2019-01-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-02
      • 1970-01-01
      • 2019-10-28
      • 1970-01-01
      相关资源
      最近更新 更多