Currently, cron service is being used to find documents that have expired and deleted them. Instead of that, we can use TTL index in a document using createdAt key in the doc. This will allow MongoDB to automatically find and remove expired documents.
More on TTL Index
Example:
// expire docs 3600 seconds after createdAt
new Schema({ createdAt: { type: Date, expires: 3600 }});
I would like to work on this
Currently, cron service is being used to find documents that have expired and deleted them. Instead of that, we can use TTL index in a document using
createdAtkey in the doc. This will allow MongoDB to automatically find and remove expired documents.More on TTL Index
Example:
I would like to work on this