I want to delete user accounts after 3 days if they don't verify their email. As a scheduler would be inefficient, I'm searching for a way to schedule this delete in MongoDB. I also need a way to cancel it, if the user verifies the email.
I'm using mgo as api for MongoDB and I'm running latest Go (1.9).
This can be achieved in MongoDB version 3.4
You can use mongodb's TTL index along with partial index expression.
Try adding following index on users
collection:
db.users.ensureIndex(
{ created_at:1},
{ expireAfterSeconds:259200,
partialFilterExpression:{"verified" : false}})
This TTL index with delete all those users who are not verified and it has been 3 days since they were added.