Weird triggers behaviour

Hi.
Im using triggers as a way to audit actions on my collections.
I recently noticed a weird behaviour regarding to the changeEvent object.
Im getting the updated fields (on update operation) from changeEvent.updateDescription.updatedFields.
It usually works as expected, but only on the first update of the document, Im getting extra data in updatedFields that did not get updated, specifically elements inside an array of objects.

example document:

{
   "firstName": "John",
   "lastName": "Depp",
   "children": [
      { "age": 20},
      { "age": 23},
  ]
}

If I will update the field firstName AND its the first update of this document, the updatedFields will contain:

{
    "firstName": "Johnny",
    "childrens.0.name": 20,
    "childrens.1.name": 23,
}

(notice that lastName was not included)

I made sure that the query of first update was the same as the rest of the update queries.

Im using mongodb version 5.0.14 on mongoDb Atlas

Hi @Lidor_Shoshani - Welcome to the community!

Thanks for clarifying the environment and MongoDB version :slight_smile: I assume you’ve created a Database Trigger for this since it’s on Atlas but please correct me if i’m wrong here.

Would you be able to provide the specific update command used?

Additonally, I noticed the childrens field containing objects with the name field present in the updatedFields value you provided but not in the original example document. Is this part of the update or was this supposed to be age instead of name?

Regards,
Jason

1 Like

Thats my mistake, it’s supposed to be age.

correct.

As we are using orm in our app (prisma) the update does include the whole document (and its a bit complicated), however, I did check and the update command is basically the same except the field that I’m updating (and updatedAt that we have), so there should not be a difference between the first update and the rest of them.