title: MongoDB 2.6 aggregation updates the $out collection
body: <p>I'm currently using MongoDB 2.6 through MongoHQ. I've several mapreduces jobs which crunch raw data from a collection (c1) to produce a new collection (c2).
  I've also an aggregation pipeline which parses (c2) to generate a new collection (c3) with the great $out operator.</p>
  
  <p>However, I need to add extra fields to (c3) outside of the aggregation pipeline and keep them even after a new run of the aggregation but it seems that aggregation, based on the _id key just overwrite the content without updating it. So if I've previously add an extra field like foo : 'bar' to (c3) and I re-run the aggregation, I will loose the foo field.</p>
  
  <p>Based on documentation (<a href="http://docs.mongodb.org/manual/reference/operator/aggregation/out/#pipe._S_out" rel="nofollow">http://docs.mongodb.org/manual/reference/operator/aggregation/out/#pipe._S_out</a>)</p>
  
  <blockquote>
    <p><strong>Replace Existing Collection</strong></p>
    
    <p>If the collection specified by the $out operation already exists, then upon completion of the aggregation, <strong>the $out stage atomically replaces the existing collection with the new results collection</strong>. The $out operation does not change any indexes that existed on the previous collection. If the aggregation fails, the $out operation makes no changes to the pre-existing collection.</p>
  </blockquote>
  
  <p>Is there a better way or a tricky one :-) to update the $out collection instead of overwriting records with same _id ? I could write a python script or javascript to do the job but I would to avoid doing many database calls and in a smarter way as aggregation. May be it is not possible, so I will look for a different and more 'classical' path.</p>
  
  <p>Thanks for your help</p>