I’m trying to have a trigger fire when a nested array is updated. I can’t seem to get the match statement to fire when this array is modified. This is basically what is returned in the change event.
I will need to test that to see if it’s possible.on trigger level , but have you considered parsing on trigger function and acting only on specific document?
Sorry to re-open this post, but I have the same issue.
Is there’s a way today to to this ?
It’s not really a problem to parse in the function but i’m confused about the billing of the triggers and the fact that we can’t filter a nested array.
In my case, i have a collection who contain an array and i need to watch for 2/3 kinds of update of an object in this array, but if the trigger is called at every update on this collection, it will be usefull for like 5% of theses calls.
So, potentially, we will be charged for a lot of useless calls in this trigger or it’s not related ?
This doesn’t appear to be possible for a nested array because the updatedField key includes the array index which can’t be accounted for, as illustrated earlier in the thread:
I have a similar issue with my trigger’s match expression.
I have records with the following matrix field:
I want my trigger to fire every time an update is detected in matrix.items. Is it possible?
My match expression is: {"updateDescription.updatedFields.matrix.items":{"$exists":true}} . But this doesn’t seem to work (maybe because matrix.items is an array?). The trigger doesn’t fire.
When it comes to arrays, the challenge is the index part (i ) of the field name "matrix.items.i.field" , which dynamically represents what element in the array has been updated.
So, the rule to match those events would involve a regular expression, matching all "matrix.items.i.field no matter the value of i or field:
By tweaking the regex part of this rule, it can be applied to any other use case where a trigger needs to fire from an update to an array element.
For example, if the trigger needs to fire only when the pos field updates, ignoring updates to context_id or date_added fields, changing regex to "^matrix\\.items\\..*\\.pos$" would provide that functionality.
The rest of the event handling logic must then be implemented in the corresponding Function.
To set up a Realm Trigger that matches an update on a nested array, you’ll need to carefully configure the trigger’s match expression to monitor the specific changes you’re interested in.
Step 1: Define the Trigger
Create a new trigger in your MongoDB Realm app, selecting the appropriate collection. Choose the “Update” operation type to monitor updates.
Step 2: Match Expression
In the match expression, use MongoDB query syntax to target the specific nested array. For example, if your documents look like this:
My other use case is that I dont want to be triggered if a value is remove from the array
I would like to know how would be the filter if i just want to be triggered if a value is added to the array?