'Mongo 'expireAfterSeconds', change field state instead of delete

Is there any way in Mongo to have a field value mutate on a trigger such as expireAfterSeconds?

For our scenario we have an invitation that we want to transition to state: 'expired' when the expireAfterSeconds takes effect, rather than having the document deleted.

Is this possible and if so, how would we go about it?

We are using Mongo by means of Mongoose and NodeJS, if that changes anything.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source