habitica/migrations/20130128_remove_dummy_accounts.js
2013-01-28 15:12:28 -05:00

19 lines
No EOL
711 B
JavaScript

// run with %mongo server:port/dbname node_modules/moment/moment.js migrations/my_commands.js
var unRegistered = { 'auth.local': { $exists: false }, 'auth.facebook': { $exists: false} },
registered = { $or: [
{ 'auth.local': { $exists: true } },
{ 'auth.facebook': { $exists: true} }
]};
db.users.count(registered);
db.users.count(unRegistered);
db.users.find(unRegistered).forEach(function(user) {
var lastCron = new Date(user.lastCron),
today = new Date(),
diff = Math.abs(moment(today).sod().diff(moment(lastCron).sod(), 'days'));
if (diff > 30) {
db.users.remove({ _id: user._id });
}
});
db.users.count(registered);
db.users.count(unRegistered);