数据对于v1.0的新Firebase云功能有哪些字段?

时间:2018-04-05 14:38:57

标签: 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.eventId; 
const timestamp = context.timestamp;
const eventType = context.eventType; 
const resource = context.resource;

});

1 个答案:

答案 0 :(得分:2)

您应该可以访问以下字段:

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
});

如文档中所述:https://firebase.google.com/docs/functions/beta-v1-diff#event_parameter_split_into_data_and_context(“事件数据现在是数据快照”)