[英]onUpdate cloud function is not working with firestore data
i have a firestore collection where i have a field like category with few values like category 1, category 2. I have a cloud function which is getting me the total count and duration of category 1 and category 2.我有一个 firestore 集合,其中有一个像类别这样的字段,其中只有几个值,如类别 1、类别 2。我有一个云 function,它让我得到类别 1 和类别 2 的总数和持续时间。
This function is working fine for create.这个 function 可以正常创建。 But when i update it, count is getting updated but duration is not.但是当我更新它时,计数正在更新但持续时间没有。 This is my update function;这是我的更新 function;
export const updateDuration =
functions.firestore.document('Duration/{userId}/Duration/{uid}')
.onUpdate(async(change, context) => {
const oldData = change.before.data();
const newData = change.after.data();
const Duration = newData.WorkDuration;
if (newData.WorkDuration == oldData.WorkDuration) {
return null } else {
const Ref = newData.parent!
Ref.set({
Duration: Duration
})
}
return null
})
The return null
probably terminates function before the set()
promise is resolved.在解决set()
promise 之前, return null
可能会终止 function。 Try this:尝试这个:
export const updateDuration =
functions.firestore.document('Duration/{userId}/Duration/{uid}')
.onUpdate(async (change, context) => {
const oldData = change.before.data();
const newData = change.after.data();
const Duration = newData.WorkDuration;
if (newData.WorkDuration == oldData.WorkDuration) {
return null
} else {
const Ref = newData.parent!
return Ref.set({ // add return here
Duration: Duration
})
}
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.