在Firebase中使用onUpdate函数时,如何检索已更新的记录?

Rya*_*yan 5 javascript firebase firebase-realtime-database google-cloud-functions

在Firebase上使用Cloud函数和onUpdate触发器时,如何检索已更新的记录(换句话说,触发该函数的记录)?我正在使用JavaScript与Firebase数据库进行交互。

Dou*_*son 6

传递给onUpdate处理函数的第一个参数是Change对象。该对象有两个属性,beforeafter,两个都是DataSnapshot对象。这些DataSnapshot对象描述了触发函数的更改前后的数据库内容。

exports.foo = functions.database.ref('/location-of-interest')
.onUpdate((change) => {
    const before = change.before  // DataSnapshot before the change
    const after = change.after  // DataSnapshot after the change
})
Run Code Online (Sandbox Code Playgroud)