From e747e8f2b9d77b365c5ba792f299d87895dded6c Mon Sep 17 00:00:00 2001 From: Tyler Renelle Date: Mon, 28 Jan 2013 15:12:28 -0500 Subject: [PATCH] add remove_dummy_acounts migration --- migrations/20130128_remove_dummy_accounts.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 migrations/20130128_remove_dummy_accounts.js diff --git a/migrations/20130128_remove_dummy_accounts.js b/migrations/20130128_remove_dummy_accounts.js new file mode 100644 index 0000000000..964c307206 --- /dev/null +++ b/migrations/20130128_remove_dummy_accounts.js @@ -0,0 +1,19 @@ +// 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); \ No newline at end of file