如何在将子项添加到数据库时触发云功能?

时间:2017-08-29 23:13:00

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

如何修改以下代码,以便功能仅在添加子项时触发 ?目前,只要指定的引用发生了变化,就会触发函数...

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!

});

1 个答案:

答案 0 :(得分:3)

使用onCreate()处理程序代替onWrite()

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

.onCreate(event => {

//child is added. Do something!

});