meteor-user-status icon indicating copy to clipboard operation
meteor-user-status copied to clipboard

How to delete/remove user if he last logged in 'x' days ago?

Open chauhanshubham-dev opened this issue 9 years ago • 3 comments

I did something like this. The error: Exception in setInterval callback: TypeError: undefined is not a function

var days = 1; Meteor.setInterval(function() { var days_ago = new Date(new Date.getTime() - (360000 * 24 * days)) Meteor.users.find({'status.lastLogin.date': {$lte: days_ago}}).forEach(function(user) { Meteor.users.remove({_id: user._id}, true); });
}, (360000 * 24 * 1));

chauhanshubham-dev avatar Jun 01 '15 03:06 chauhanshubham-dev

Meteor does something similar by pruning stale login tokens from the database, search for _expireTokens in the following:

https://github.com/meteor/meteor/blob/devel/packages/accounts-base/accounts_server.js#L1044

mizzao avatar Jul 09 '15 13:07 mizzao

I used javascript to solve this problem. Running the script after every 'y' hours, and deleting the users as required. But if meteor has something inbuilt, then I'll surely look into it

Thanks

chauhanshubham-dev avatar Jul 09 '15 13:07 chauhanshubham-dev

That built-in function is not doing the same thing; I just pointed to it as an example that was doing something similar.

mizzao avatar Jul 09 '15 13:07 mizzao