For my USERS collection, I want to trigger a function when a document is inserted or updated, but only if the “status” field of the inserted/updated document is not equal to an empty string.
Reading the documentation, I believe with the $match expression, I can look to see if the value of “status” is CHANGED to an empty string using the expression below:
But that is not what I want. I want to fire the trigger only if the value for “status” field AFTER update or insert is NOT an empty string. It could have been an empty string before update as well.
The solution so far for me is to let the trigger get fired, but then in the function I check for the value of the “status” field to do what I need to do, but that means the trigger will be fired too many unnecessary times since the “status” field has an empty string 80% of the time.
Hi @Pavel_Duchovny,
Thanks for the response. However, I think with this expression, the trigger will still be fired if the “status” value was originally an empty string and after the document is updated, it’s still an empty string (the update happened on other fields). Right?
What I am trying to accomplish is to check the “status” value AFTER THE UPDATE and no matter what the previous value was, if the new value is equal to an empty string, I do not want to fire the trigger. Is that possible?
Hi @Pavel_Duchovny,
I think that’s it. It works now the way I want it to. I did not know that we have access to the fullDocument in the Realm UI. That’s great!
Seems like this is already accounted for. We do have access to fullDocument in the Realm UI and so we can do the check in the advanced section using what Pavel suggested.