当我ignore
在Firebase数据库中的字段更改时,我试图触发一个触发器。
const functions = require('firebase-functions');
const admin = require('firebase-admin')
admin.initializeApp(functions.config().firebase)
// // Create and Deploy Your First Cloud Functions - All runs in the Firebase Server, not in the Browser
// // https://firebase.google.com/docs/functions/write-firebase-functions
exports.dbTest = functions.database.ref('/{uid}/ignore')
.onUpdate((snap, context) => {
return snap.ref.child('new').set('dddddd')
});
为了进行简单的测试,我在onUpdate
ref上创建了一个触发器,该触发器/{uid}/ignore
指向下图所示的内容。我期望手动更改字段时会触发此操作(例如,ignore/endTime
但是什么也没发生。我对此并不陌生,所以我很困惑如何使用它。请帮忙。
编辑
该函数被触发,但是没有任何反应。日志显示Function execution took 224 ms, finished with status: 'error'
没有任何有用的日志消息。
您似乎误读了签名。该onUpdate()
触发器被称为一个Change
对象。从该对象可以获取快照before
和after
更新,而从任一对象都可以获取引用。
所以:
exports.dbTest = functions.database.ref('/{uid}/ignore')
.onUpdate((change, context) => {
return change.after.ref.child('new').set('dddddd')
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句