1.0版新Firebase云函数的数据包含哪些字段?

1.0版新Firebase云函数的数据包含哪些字段?,firebase,firebase-realtime-database,google-cloud-functions,Firebase,Firebase Realtime Database,Google Cloud Functions,以下是最新firebase云函数SDK上非HTTP的代码 exports.dbWrite = functions.database.ref('/pat/with/{id}').onWrite((data, context) => { const authVar = context.auth; const authType = context.authType; const pathId = context.params.id; const eventId = context.e

以下是最新firebase云函数SDK上非HTTP的代码

exports.dbWrite = functions.database.ref('/pat/with/{id}').onWrite((data, context) => {    
const authVar = context.auth; 
const authType = context.authType;
const pathId = context.params.id; 
const eventId = context.eventId; 
const timestamp = context.timestamp;
const eventType = context.eventType; 
const resource = context.resource;

});

您应该能够访问如下字段:

exports.dbWrite = functions.database.ref('/path').onWrite((data, context) => {
  const beforeData = data.before.val(); // data before the write
  const afterData = data.after.val(); // data after the write
});

如文档中所述:(“事件数据现在是一个数据快照”)

在链接的第一部分是,但您必须向下滚动到我在回答中引用的“事件数据现在是一个数据快照”部分。我可以访问文档中的方式,但得到空值@Leonardo G能否在AllyMakongo分享/更新代码片段?正如你正在使用它一样,我已经修复了它。问题是如何使用最新的sdk从json树中提取数据。是的,链接上的文档会告诉您v1云函数的变化。很高兴你修好了!