I have a realm function built firing off a database trigger. I need to add a match expression to filter the trigger, otherwise it will run on a continuous loop because it is updating the same collection that triggers it.
So my match expression is this:
{“updateDescription.updatedFields.profile”:{"$exists":true}}
When I go into my collection and update a document’s “profile” field, nothing happens. When I take away the match expression, it runs all the time, but it runs in a continuous loop like mentioned before.
Hi Pavel, it seems that something is off with the way the match gets pasted In reality, the quotes are just fine in the match statement. I tried to fix them, but they are already set to the correct character type.
So the inifinite loop issue is exactly why I need the match statement
Basically, if the profile field is updated, I want the trigger to run.
The trigger will run a function that will update the recommendations field, so that’s why I need the match statement to filter that update out. If recommendations is updated, or any change event that does not include an update to profile, I don’t want the function to run. But if the event includes profile, I do want it to run.
That way, when the function updates recommendations and does not update profile, the trigger will not get run, and there will be no infinite loop.
After doing a lot of logging, I noticed something. For context, I have been testing by updating the document from within the Atlas UI. Apparently, doing so triggers a replace operation? Didn’t know that but, very interesting.
Anyway, once I figured that out I was able to implement the logic needed to only fire my function when I want. Thanks so much for your help and the great idea!