Skip to content

Instantly share code, notes, and snippets.

@tony4d
Created March 5, 2011 01:30
Show Gist options
  • Save tony4d/856009 to your computer and use it in GitHub Desktop.
Save tony4d/856009 to your computer and use it in GitHub Desktop.
Simple way to change data in mongo using existing data in a document
// Here my collection is named articles
// I'm changing the blog_name field in every document in that collection to lowercase
db.articles.find().forEach(function(doc){if(typeof(doc.blog_name) == 'string') {doc.blog_name = doc.blog_name.toLowerCase(); db.articles.save(doc); }})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment