title: Mongodb insert new field across collection based on existing field
body: <p>I need to update every record in a collection with a new field.  </p>
  
  <p>My documents look something like:</p>
  
  <pre><code>{
    words:['apple','banana','porridge']
  } 
  </code></pre>
  
  <p>and I want to add a new field called word_count that holds the length of the words array (the array length is static).</p>
  
  <pre><code>{
    words:['apple','banana','porridge'],
    word_count : 3
  } 
  </code></pre>
  
  <p>I've tried things along the lines of:</p>
  
  <pre><code>update({}, {$set: {word_count: words.length}}, {multi: true});
  </code></pre>
  
  <p>And I could do a forEach, however we are talking a fairly large data set of over 2 million rows, so for each is not the most efficient... unless of course it's the only way.</p>