Trigger match update on nested array object property

Hi, I played around with this a bit and you can accomplish this via a normal aggregation pipeline like this:

[
  {
    $addFields:
      {
        updatedFieldArr: {
          $objectToArray: "$updateDescription.updatedFields",
        },
      },
  },
  {
    $match:
      {
        $or: [
          {
            "updatedFieldArr.k": {
              $regex:
                "members.[0-9]+.email_status.[0-9]+.prevalent_status",
            },
          },
          {
            "updatedFieldArr.k": {
              $regex:
                "members.[0-9]+.email_status.[0-9]+.statuses",
            },
          },
        ],
      },
  },
]

Therefore, I think you can add the first bit to the “project” and the second bit to the “match expression”. I have not tried this on a trigger through admitedly, so let me know if this works?

As an aside, I found the following process helpful for this:

  1. Download MongoDB Compass
  2. Insert some documents into a collection in the shape of your change events
  3. Use the aggregation builder

Best,
Tyler