I need to remove mongodb documents after a specified period of not being accessed.
I have a access token I use to retrieve data from an external source and save it in my database.
In my session I store a user id I can use the retrieve the access token when a user makes a request.
If my session expires the access token saved in my database will never be used again.
The user will be prompted to re-authenticate and a new access token will be saved in the database.
If the user logs out explicitly I can easily remove the now invalid access token from the database. But if they never log out and the session expires then the database entry will remain indefinitely.
I thought about detect session expiry and run a function to remove the associated access token from my database but what if the session expires when app is not running.
I think I need some kind on maintenance like a cron job or something on my database that will remove documents after a specific period of not being accessed,
How would I go about this with mongoDB?