Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
384 views
in Technique[技术] by (71.8m points)

javascript - 在Firebase中使用onUpdate函数时,如何检索已更新的记录?(When using the onUpdate function in Firebase, how do I retrieve the record that has been updated?)

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)?(在Firebase上通过onUpdate触发器使用云函数时,如何检索已更新的记录(换句话说,触发该函数的记录)?)

I am using JavaScript to interface with the Firebase database.(我正在使用JavaScript与Firebase数据库进行交互。)   ask by Ryan translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The first argument passed your onUpdate handler function is a Change object.(传递给onUpdate处理函数的第一个参数是Change对象。)

This object has two properties, before and after , both DataSnapshot objects.(该对象有两个属性,即DataSnapshot对象的beforeafter 。) These DataSnapshot objects describe the contents of the database before and after the change that triggered the function.(这些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 })

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...