I wanted to set some fields on documents based on field "timeoutOn"

Hi Team,
I hope you guys are doing well. I wanted to set one field deleted: true based on Date field timeoutOn.
So when Date.Now > timeoutOn, I want to set document as deleted: true.
Does Mongo Atlas Provides this ??
I can see I can call Mongo Functions on scheduled triggers but It would be same as any k8s cron job/ AWS lambda.


Hi @Gheri_Rupchandani,

I am not entiry sure I understand your use case but it seems you eant to expire documents after specific time on field timeOn . We have TTL indexes just for this purpose:


If you wish to update a field instead you will need a database trigger for when the field is added or updated you can run a function with the needed logic to set deleted field. To avoid a circular trigger place a match on the timeOn field only so the the deleted field won’t trigger it.


Thanks for inputs.
I think you got confused with word deleted but I want to set a field when value in timeoutOn field is passed.
For example lets say timeoutOn = 1 sept 2020 1:00:00 AM. so i want to set field deleted: true when current time (1 sept 2020 1:01:00 AM) is greater than timeoutOn value.

@Gheri_Rupchandani, In that case you need a trigger to run every lets say min and query all “undeleted” whic times passed new Date() and updating them…

Thanks for answer.
Is there a way to define the scheduled trigger in code like cloud formation in AWS ??
Also if I run update this field based on above criteria on collection will it update for million documents (matching query criteria) in collections ??

Hi @Gheri_Rupchandani,

Yes schedule triggers runs a JS function which could be linked to your atlas cluster and performing any type of crud as long as it is faster than 90s (execution limit).

I would recommend indexing the fields properly and update limited portion each time to be qble to do that in 90s.



There is one similar use-case. Here I have created a ttl index (say expiresOn) with expirySeconds as 24 hours.
now we all know document will get removed when time (expiresOn + 24hours) is passed.
I have requirement to show this document as (expired: true) when expiresOn is passed so that user can extend the time if he wants and if he does not it would automatically deleted due to TTL.
Deleteion would be handled by mongo automatically due to TTL index.
Is there any way to auto set the property expired: true when expiresOn reached ??
Or I have to follow the same method that you recommended just to set the property ??


@Gheri_Rupchandani, than I would say schedule triggers are the best solution I can think about…