title: mongodb aggregation, is it possible to add entries to an array during $project
body: <p>I have documents of the form:</p>
  
  <pre><code>{
      _id : ObjectId(.....),
      prop1 : "foo",
      links : [ 1, 2, 3, 4 ]
  }
  
  {
      _id : ObjectId(.....),
      prop1 : "bar",
      links : [ 5, 6, 7, 8 ]
  }
  </code></pre>
  
  <p>I am using the aggregation framework to process these documents, I use $unwind to generate a document for each value in the links array. </p>
  
  <p>But I have three cases where I need to update the documents before calling $unwind, I have been looking at the $project operation, but I can find no information about how to create or update arrays for the following cases.</p>
  
  <p>1) The links property is missing</p>
  
  <pre><code>{
      _id : ObjectId(.....),
      prop1 : "far"
  }
  </code></pre>
  
  <p>I need to insert the links array</p>
  
  <p>2) The links array property is an empty array</p>
  
  <pre><code>{
      _id : ObjectId(.....),
      prop1 : "far",
      links : []
  }
  </code></pre>
  
  <p>I need to insert a value into the array</p>
  
  <p>3) The links array has too few values</p>
  
  <pre><code>{
      _id : ObjectId(.....),
      prop1 : "far",
      links : [ 9, 10 ]
  }
  </code></pre>
  
  <p>I need to insert additional values into the array</p>