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

How to trigger Cloud Function only when child is added to the database?

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

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!

});

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

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

.onCreate(event => {

//child is added. Do something!

});