【发布时间】:2020-03-24 18:54:42
【问题描述】:
我不想获取 .onUpdate() 中 {id} 下的所有值 var3 是嵌套对象,而 var2 是单个变量。 那么如何从 onUpdate 中检索 {id} 并将其作为参数传递给我可以在 admin.ref() 中使用的 customMethod?
index.ts
export const funcName = functions.region("someRegion").database.ref('/user/{id}/var3').onUpdate((change, context) =>{
const originalData = <varType> change.after.val();
const processedData = customMethod(originalData);
if(change.after.ref.parent)
return change.after.ref.parent.child('custom').set(processedData);
else
return null;
});
function customMethod(data: varType){
return admin.database().ref('/user/{id}/var2').once('value').then(function(snapshot){
// processing stuff after storing value from var2 in a local variable
}
【问题讨论】:
-
请添加更多关于您的确切目标和 Firestore 数据库结构的详细信息。如果可以的话,很难理解你的目标。
标签: typescript firebase firebase-realtime-database google-cloud-functions