写入同一文档的云功能是否会再次触发自身
Does cloud function that writing to the same document trigger itself again
比如我有这个云函数
export const testFunction = functions.firestore
.document('posts/{postID}')
.onWrite((change) => {
if (!change.after.data()) return;
const { count = 0 } = change.after.data();
t.set(change.after.ref, { count: count + 1 }, { merge: true });
});
会不会因为不断更新文档字段并自己触发而陷入循环?
您的代码没有显示 t
是什么,所以我们无法确切知道这个函数在做什么。
但是,如果您在为响应同一文档的更新而触发的触发器中更新文档,则触发器将再次执行。您可以在不更新文档的情况下创建函数 return 以避免无限循环。因此,您需要弄清楚如何确定是否属于这种情况。
比如我有这个云函数
export const testFunction = functions.firestore
.document('posts/{postID}')
.onWrite((change) => {
if (!change.after.data()) return;
const { count = 0 } = change.after.data();
t.set(change.after.ref, { count: count + 1 }, { merge: true });
});
会不会因为不断更新文档字段并自己触发而陷入循环?
您的代码没有显示 t
是什么,所以我们无法确切知道这个函数在做什么。
但是,如果您在为响应同一文档的更新而触发的触发器中更新文档,则触发器将再次执行。您可以在不更新文档的情况下创建函数 return 以避免无限循环。因此,您需要弄清楚如何确定是否属于这种情况。