Skip to content

Instantly share code, notes, and snippets.

@delenamalan
Last active August 31, 2017 08:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save delenamalan/fdc4d1cff7d95790382897f08f22a10e to your computer and use it in GitHub Desktop.
Save delenamalan/fdc4d1cff7d95790382897f08f22a10e to your computer and use it in GitHub Desktop.
mm-394-script.js
var collection = db.addressbook_2;
collection.find({'fields.verificationChannel': 'iOS'}).forEach(function(doc) {
if (doc.fields && (!doc.fields.latitude || !doc.fields.longitude)) {
collection.update(
{_id : doc._id},
{$set: { "fields.requiresVerification": "true"}}
);
} else if (doc.fields && ((doc.fields.latitude && doc.fields.latitude % 1 == 0) || (doc.fields.longitude && doc.fields.longitude == 0))) {
collection.update(
{_id : doc._id},
{$set: { "fields.requiresVerification": "true"}}
);
}
});
print("Verifying");
var remaining_tasks = 0;
collection.find({'fields.verificationChannel': 'iOS'}).forEach(function(doc) {
if (doc.fields && (!doc.fields.latitude || !doc.fields.longitude) && doc.fields.requiresVerification !== "true") {
remaining_tasks = remaining_tasks + 1;
} else if (doc.fields && ((doc.fields.latitude && doc.fields.latitude % 1 == 0) || (doc.fields.longitude && doc.fields.longitude == 0)) && doc.fields.requiresVerification !== "true") {
remaining_tasks = remaining_tasks + 1;
}
});
if (remaining_tasks == 0){
print("Migration was successful");
}
else {
print("Migration has failed");
}
@dopstar
Copy link

dopstar commented Aug 29, 2017

👍

@richardwooding
Copy link

Looks ok if you tested

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment