答案 0 :(得分:0)
您在问题中使用的语法是与1.0.0之前的版本相对应的Firebase SDK for Cloud Functions。您应该使用最新版本,并使用其他语法,请参见https://firebase.google.com/docs/functions/beta-v1-diff
然后对于> = 1.0的版本,您将执行以下操作:
exports.myFunction = functions.database
.ref('/isAllowed/{pushId}')
.onWrite((change, context) => {
// const beforeData = change.before.val(); data before the write
const afterData = change.after.val(); // data after the write
console.log(afterData); // -> you get false
return change.after.ref.set(true); // -> you update to e.g. true
});
如上述文档中所述
对于onWrite和onUpdate事件,data参数具有before和 后田。这些都是具有相同方法的DataSnapshot 在
admin.database.DataSnapshot
中可用。
因此,在上面的代码中,我们使用此DataSnapshot的ref
属性通过set()
方法(也可以使用update()
)对其进行更新。