我尝试在 Firebase 数据库中的ignore
字段发生更改时触发。
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')
});
为了进行一个简单的测试,我在 ref /{uid}/ignore
上创建了一个 onUpdate
触发器,它指向下图所示的内容。我本以为当我手动更改字段时会触发此操作(假设ignore/endTime
),但什么也没发生。我对此很陌生,所以我很困惑如何使用它。请帮忙。
编辑
函数被触发但没有任何反应。日志显示函数执行花费了 224 毫秒,完成状态为:“错误”
,没有任何有用的日志消息。
最佳答案
您似乎误读了签名。使用 Change
object 调用 onUpdate()
触发器。从该对象中,您可以获取更新之前
和之后
的快照,并且可以从其中任何一个获取引用。
所以:
exports.dbTest = functions.database.ref('/{uid}/ignore')
.onUpdate((change, context) => {
return change.after.ref.child('new').set('dddddd')
});
关于javascript - 使用 Firebase 数据库触发器 onUpdate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55779718/