Skip to content

Instantly share code, notes, and snippets.

@zohar
Created February 24, 2015 21:38
Show Gist options
  • Star 15 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save zohar/a047e265e336b329f811 to your computer and use it in GitHub Desktop.
Save zohar/a047e265e336b329f811 to your computer and use it in GitHub Desktop.
MongoDB: Find by regular expression and run regex replace on results
/*
MongoDB: Find by regular expression and run regex replace on results
*/
db.test.find({"url": { $regex: 'http:\/\/' }}).forEach(function(doc) {
doc.url = doc.url.replace(/http:\/\/www\.url\.com/g, 'http://another.url.com');
db.test.save(doc);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment