title: How to Quickly Update Mongo Documents String Fields with Complex Functions
body: <p>What is the fastest way to update documents in a Mongo database with complex functions, let's say a string search / replace or a <code>sqrt</code> calculation?</p>
  
  <p>Since such operations are missing, e.g. a <code>$replace</code>, it is not possible with <code>update</code> (which would probably be the fastest, since on my test collection it only takes about 50 ms to set a field on some 100k objects).</p>
  
  <p>When I simply iterate over all documents it takes about 45 seconds. It gets a little faster when I limit my query to the fields I'm using during the update.</p>
  
  <p>This time of course grow larger on larger collections, therefore the question whether there is a faster way than iterating over the collection (e.g. via a map reduce job?).</p>