Auto-update an updatedAt timestamp

I need a good way to know if a record has been changed so I can ETL changes (and new docs) into a data warehouse. We have several front-end dev teams working in Mongo, and several projects already in place that do not have this, or at least not well/correctly. I’m considering a trigger that will update a new etlUpdate timestamp or bool on the document, but will that cause a never-ending loop? I.e., “something changed, update that new field, ooh, that also changed, update it again…”.

Or is there a better way to do this without making my dev teams update their code anywhere they’re doing an update?

Use MarshalBSON, then init item := & model.File{}, item.Name = input.Name,… your updated field auto updated.

func (i *File) MarshalBSON() (byte, error) {
now := primitive.Timestamp{T: uint32(time.Now().Unix())}

if i.Created.IsZero() {
	i.Created = now
}

i.Updated = now
i.Nonce = primitive.NewObjectID()

type t File
return bson.Marshal((*t)(i))

}