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 |
---|---|---|---|
Error loading RealmSwift framework in iOS app | 1 | 1.8k | May 2024 |
Crash in iOS - [RLMRealm verifyThread] | 2 | 240 | Aug 2024 |
realm sdk Can we add agents | 0 | 140 | Aug 2024 |
Wait for synchronization takes too long | 0 | 56 | Aug 2024 |
.NET Sync SDK Retrieve Single Field Value w/o Instantiation | 1 | 28 | Sep 2024 |