From b75f044d07bc9cefe9d62b859209db1887b1173b Mon Sep 17 00:00:00 2001 From: kylestratis Date: Sun, 25 Oct 2015 18:16:42 -0400 Subject: [PATCH 1/4] Changed Mongo query to check DateTerminated to prevent accumulation of mystery items when subscription is ended. --- migrations/mystery_items.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/migrations/mystery_items.js b/migrations/mystery_items.js index 48f2009b15..9a7b37eec4 100644 --- a/migrations/mystery_items.js +++ b/migrations/mystery_items.js @@ -27,6 +27,6 @@ if (_id) { db.users.update({_id:_id}, update); } else { // multiple (once @ start of event) - db.users.update({'purchased.plan.customerId':{$ne:null}}, update, {multi:true}); + db.users.update({$and: [{'purchased.plan.customerId':{$ne:null}},{$or: [{'purchased.plan.dateTerminated':{$gte:new Date()}},{'purchased.plan.dateTerminated':{$eq:null}}]}]}, update, {multi:true}); } From be3fe8f1f45f3682ec8cd428739d43a1fa9edc0f Mon Sep 17 00:00:00 2001 From: kylestratis Date: Sat, 31 Oct 2015 22:08:16 -0400 Subject: [PATCH 2/4] Added check for existence of dateTerminated field --- migrations/mystery_items.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/migrations/mystery_items.js b/migrations/mystery_items.js index 9a7b37eec4..611544f294 100644 --- a/migrations/mystery_items.js +++ b/migrations/mystery_items.js @@ -27,6 +27,9 @@ if (_id) { db.users.update({_id:_id}, update); } else { // multiple (once @ start of event) - db.users.update({$and: [{'purchased.plan.customerId':{$ne:null}},{$or: [{'purchased.plan.dateTerminated':{$gte:new Date()}},{'purchased.plan.dateTerminated':{$eq:null}}]}]}, update, {multi:true}); -} - + db.users.update([{$and: [{'purchased.plan.customerId':{$ne:null}}, + {$or: [{'purchased.plan.dateTerminated':{$gte:new Date()}}, + {'purchased.plan.dateTerminated':{$exists:false}}, + {'purchased.plan.dateTerminated':{$eq:null}}]}]}], update, {multi:true}); + }); +} \ No newline at end of file From 77ded02fa0dadf3f204fc71f59dc87beba043c8f Mon Sep 17 00:00:00 2001 From: kylestratis Date: Wed, 11 Nov 2015 21:05:08 -0500 Subject: [PATCH 3/4] Formatting changes for readability --- migrations/mystery_items.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/migrations/mystery_items.js b/migrations/mystery_items.js index 611544f294..3c9cf93661 100644 --- a/migrations/mystery_items.js +++ b/migrations/mystery_items.js @@ -27,9 +27,14 @@ if (_id) { db.users.update({_id:_id}, update); } else { // multiple (once @ start of event) - db.users.update([{$and: [{'purchased.plan.customerId':{$ne:null}}, - {$or: [{'purchased.plan.dateTerminated':{$gte:new Date()}}, - {'purchased.plan.dateTerminated':{$exists:false}}, - {'purchased.plan.dateTerminated':{$eq:null}}]}]}], update, {multi:true}); - }); + db.users.update([ + {$and: [ + { 'purchased.plan.customerId': { $ne:null } }, + {$or: [ + { 'purchased.plan.dateTerminated': { $gte: new Date() } }, + { 'purchased.plan.dateTerminated': { $exists:false } }, + { 'purchased.plan.dateTerminated': { $eq:null } } + ]} + ]} + ], update, { multi:true }); } \ No newline at end of file From b5efa4ae4c576de35bbcd184beefc0b4b6e2c856 Mon Sep 17 00:00:00 2001 From: kylestratis Date: Wed, 11 Nov 2015 21:25:22 -0500 Subject: [PATCH 4/4] Additional formatting --- migrations/mystery_items.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/migrations/mystery_items.js b/migrations/mystery_items.js index 3c9cf93661..ad324e378d 100644 --- a/migrations/mystery_items.js +++ b/migrations/mystery_items.js @@ -1,8 +1,8 @@ var _id = ''; var update = { $addToSet: { - 'purchased.plan.mysteryItems':{ - $each:['head_mystery_201509','armor_mystery_201509'] + 'purchased.plan.mysteryItems': { + $each: ['head_mystery_201509', 'armor_mystery_201509'] } } }; @@ -24,17 +24,17 @@ var update = { if (_id) { // singular (missing items) - db.users.update({_id:_id}, update); + db.users.update({_id: _id}, update); } else { // multiple (once @ start of event) db.users.update([ {$and: [ - { 'purchased.plan.customerId': { $ne:null } }, + { 'purchased.plan.customerId': { $ne: null } }, {$or: [ { 'purchased.plan.dateTerminated': { $gte: new Date() } }, - { 'purchased.plan.dateTerminated': { $exists:false } }, - { 'purchased.plan.dateTerminated': { $eq:null } } + { 'purchased.plan.dateTerminated': { $exists: false } }, + { 'purchased.plan.dateTerminated': { $eq: null } } ]} ]} - ], update, { multi:true }); + ], update, { multi: true }); } \ No newline at end of file