Does cloud function that writing to the same document trigger itself again

Kevin

For example I have this cloud function

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

Will it be stuck in a loop since it's constantly updating the document field and triggering itself?

Doug Stevenson

Your code does not show what t is, so we can't tell exactly what this function is doing.

But if you are updating a document within a trigger that fired in response to an update on that same document, the trigger will execute again. It's up to you to make the function return without updating the document in order to avoid an infinite loop. So, you will need to figure out how to determine if that's the case.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

cloud function trigger on create document

Cloud function trigger on document update

Lambda trigger a function itself

How to trigger a cloud function based on a timestamp attribute of a firestore document

Does Google Cloud Storage uploading trigger a Firebase Cloud function?

Writing a Swift function that returns itself

Trigger Firebase Cloud Function on inserting to Cloud Firestore document for the first time with given uid

Does Firebase Cloud Function Trigger Parallel or One by One?

Load local file if no internet connection; function calls itself again and again

performance for writing the same value again into cache line

How to repeat a code in html without writing the same code again and again

Does PERFORM inside of a trigger execute a function in the same transaction as the caller?

Firestore cloud function querying for database: Document does not exist

Cloud function: No document found

How to access root document when using a firestore trigger (onUpdate) in my cloud function?

How to update or set property of firestore document after .onCreate cloud function trigger

Trigger cloud function when a specific condition resulting from the comparison of document fields in firestore is true

Delete document in Firestore with Cloud Firestore update trigger

Does a cloud function have the same cost as a regular query from client?

Cloud function trigger for multiple collections

Trigger Firebase Cloud Function on linkWithCredential()

Function writing to the same dictionary or just not writing in it at all

Exit function and call itself again without returning undefined

Cloud Function's Cloud Firestore trigger

Cloud Firestore trigger for Cloud Function to invoke Composer

How to avoid writing same code over again in UIViewController in Swift?

StreamWriter keeps writing to the same file after instantiating it again for another file

Function firing at same time by trigger

how to stop to call the same function again and again in JavaScript?