title: MongoDB Convert Array of Objects to Single Object
body: <p>Using a MongoDB aggregate query, how do I convert an array of documents to a single document. The array can have N number of documents.</p>
  
  <p><strong>Before</strong></p>
  
  <pre><code>"loop" : [
      {
          "field1" : "1"
      }, 
      {
          "field2" : "2", 
          "field3" : "3", 
      }, 
      {
          "field4" : "4", 
      }, 
      {
          "field5" : "5", 
          "field6" : "6"
      }
  ]
  </code></pre>
  
  <p><strong>After</strong></p>
  
  <pre><code>"loop" : {
      "field1" : "1",
      "field2" : "2", 
      "field3" : "3", 
      "field4" : "4", 
      "field5" : "5", 
      "field6" : "6"
  }
  </code></pre>