Created
November 18, 2014 19:30
-
-
Save alexserver/feb98899bbb2254a5f66 to your computer and use it in GitHub Desktop.
update many records in mongodb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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