Skip to content

Instantly share code, notes, and snippets.

@alexserver
Created November 18, 2014 19:30
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 alexserver/feb98899bbb2254a5f66 to your computer and use it in GitHub Desktop.
Save alexserver/feb98899bbb2254a5f66 to your computer and use it in GitHub Desktop.
update many records in mongodb
//in SQL
update mydoc set word = replace(word, 'some_undesired_word', '')
//in mongodb
db.mydoc.find().forEach(function(doc){
if (!doc.word) return;
doc.word = doc.word.replace('some_undesired_word', '');
db.mydoc.update({_id : doc._id}, {"$set":{"word":doc.word}});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment