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:
{
"$expr": {
"$gt": [
{
"$size": {
"$filter": {
"input": { "$objectToArray": "$updateDescription.updatedFields" },
"cond": { "$regexMatch": { "input": "$$this.k", "regex": "^matrix\\.items\\..*$" } }
}
}
},
{ "$numberInt": "0" }
]
}
}
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.
Best,
Alex