Is it possible to update a field in an Update/Insert document trigger without it refiring the trigger multiple times due to the change? I suspect this just isn’t possible but thought I’d ask
Thanks!
-Shane
Is it possible to update a field in an Update/Insert document trigger without it refiring the trigger multiple times due to the change? I suspect this just isn’t possible but thought I’d ask
Thanks!
-Shane
Hi, it sounds like your trigger is reacting to itself. IE, the trigger is listening to a collection and modifying that same collection. That means that every time the trigger runs and updates the document it will cause another event to fire and update the document (and then another).
You will need to short-circuit this by not performing the write if the update being made is from this function code (you can examine the contents of the changeEvent / updateDescription for this)
Some pseudo-code would be:
if changeEvent.operationType === "update" && changeEvent.updateDescription.length === 1 && changeEvent.updateDescription["modifiedAt"] !== undefined {
return
}
I saw your other post in which you are updating the “modifiedAt” field. So the idea is just that if we can identify that this is just a trigger running, then we can stop executing the function.
Hi,
Yep, that method seems like it should work. I removed the other post because I figured out why it was retriggering but didn’t know how to prevent it.
Thanks for the help!
-Shane
Topic | Replies | Views | Activity |
---|---|---|---|
Blank page when I click ‘app services’ button? | 0 | 302 | May 2024 |
Example Authentication codebase | 3 | 402 | Jun 2024 |
Vue + Realm = Persistence Data ? | 0 | 369 | Jun 2024 |
Realm sync for specific multiple user | 0 | 156 | Aug 2024 |
Is there a way to view my Realm DB (from my iPhone) on my Mac? | 0 | 49 | Oct 2024 |