How to Listen for Document Expiration in MongoDb

Viewed 8

Imagine I have the following document schema created via Mongoose

new TokenSchema({token:String,owner_email:String, type:String, createdAt: { type: Date, expires: 3600 }});

The above document is meant to expire 60m after creation.

Now, I need a way to know when the token is about to be auto deleted at the due time.

This is because I need to send an email to the owner of the token before the token gets deleted.

Is there an onBeforeDestroy listener or how can this be handled?

My use case is Mongoose and NodeJS

Thanks

0 Answers
Related