Realm Trigger match on nested array update

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:

json

{
  "parentField": {
    "nestedArray": [
      { "key": "value" },
      { "key": "value" }
    ]
  }
}

You can match updates to nestedArray using:

json

{
  "updateDescription.updatedFields": {
    "$regex": "^parentField.nestedArray\\..*"
  }
}
1 Like