Skip to content

Instantly share code, notes, and snippets.

@crocker
Last active November 17, 2016 14:45
Show Gist options
  • Save crocker/7780d2361b2fb2e505950ed2de0a1c9e to your computer and use it in GitHub Desktop.
Save crocker/7780d2361b2fb2e505950ed2de0a1c9e to your computer and use it in GitHub Desktop.
db.getCollection('patient').find().snapshot().forEach(
function (p) {
var lower_middle_name;
if(p.middle_name) lower_middle_name = p.middle_name.toLowerCase(); else lower_middle_name = null;
var lower_mrn;
if(p.mrn) lower_mrn = p.mrn.toLowerCase(); else lower_mrn = null;
var lower_email_address;
if(p.email_address) lower_email_address = p.email_address.toLowerCase(); else lower_email_address = null;
// update document, using its own properties
p.lower_first_name = p.first_name.toLowerCase();
p.lower_middle_name = lower_middle_name;
p.lower_last_name = p.last_name.toLowerCase();
p.lower_mrn = lower_mrn;
p.lower_email_address = lower_email_address;
// save the updated document
db.getCollection('patient').save(p);
}
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment