Realm Trigger match on nested array update

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.

[
  {"updatedFields":{"TopLevelArray.1.NestedArray.0.desc":"Test Value"},"removedFields\":[]}
]

I’m trying to match with the following but it doesn’t seem to work since the indexes are in the “updatedFields” document.

{"updateDescription.updatedFields.TopLevelArray.NestedArray":{"$exists":true}}

I would like for it to match when anything at all in “NestedArray” is changed.

Any ideas of how I can accomplish this?

Hi @Tyler_Queen,

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?

Thanks
Pavel

Yes, I’m doing that in the attached function I just don’t want the trigger to fire every time the collection is updated.

Hi @Tyler_Queen ,

I could not find a way to do this on the match trigger expression as the field has a string path with “.” in its key :frowning:

So the only way I see is at the moment is in the function…

Thanks
Pavel

Hi,

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 ?

Hi Pierre,

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:

{"updatedFields":{"TopLevelArray.1.NestedArray.0.desc":"Test Value"}

If it were a nested field (not array) being updated, then this could be used:

{"$expr":{"$eq":[{"$let":{"in":{"$size":"$$foo"},"vars":{"foo":{"$filter":{"cond":{"$eq":["topLevelField.nestedField","$$this.k"]},"input":{"$objectToArray":"$updateDescription.updatedFields"}}}}}},{"$numberInt":"1"}]}}

Regards

1 Like

I have a similar issue with my trigger’s match expression.

I have records with the following matrix field:
Screenshot 2022-05-03 at 11.41.11

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.