How to stop iteration of trigger when update document?

I inserted trigger date using atlas trigger when document insert or update operations. But trigger date field updated every time. Because that trigger method running infinite. How I avoiding it?

I am not sure I follow your question. My interpretation is that you have a trigger on a collection where you then update that same collection which then causes the trigger to fire again.

One way to avoid this is to tag the “trigger’s update” with some information that you can use the MatchExpression to filter it out. IE, you can add a fromTriggerCount field to the document and have the trigger function do a $inc on that field. Then your match expression for the trigger can include something like:

{ updateDescription.updatedFields.fromTriggerCount`: {$exists: false}}

@Tyler_Kaye Can we make a feature request where MongoDB adds “triggerUpdate” to the list of events that are detected as trigger conditions? That way the first Update event activates the trigger, which updates a document within the collection. That event is a “triggerUpdate,” and thus doesn’t re-activate the original Update trigger.

Adding a field just to track the number of times a trigger has executed isn’t always desirable. And my use case is different: I may need documents to be re-evaluated at a later date, so excluding them because they were evaluated in the past isn’t good.

Thanks!