在Firebase中使用onUpdate函数时,如何检索已更新的记录? [英] When using the onUpdate function in Firebase, how do I retrieve the record that has been updated?
问题描述
在Firebase上使用云功能时,通过onUpdate触发器,我如何检索已更新的记录(换句话说,触发该功能的记录)?我正在使用JavaScript与Firebase数据库进行交互.
When using the cloud functions on firebase, with the onUpdate trigger, how do I retrieve the record that has been updated (in other words, the record that triggers the function)? I am using JavaScript to interface with the Firebase database.
推荐答案
第一个参数通过了 onUpdate 处理函数是更改一个>对象.此对象具有两个属性,之前
和之后
,均为 DataSnapshot 对象.这些DataSnapshot对象描述了触发函数的更改前后的数据库内容.
The first argument passed your onUpdate handler function is a Change object. This object has two properties, before
and after
, both DataSnapshot objects. These DataSnapshot objects describe the contents of the database before and after the change that triggered the function.
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
})
这篇关于在Firebase中使用onUpdate函数时,如何检索已更新的记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!