title: $setUnion to merge array from multiple documents MongoDB
body: <p>I have documents in a collection as follows :</p>
  
  <pre><code>{ _id : 1 , data : [7,4,0] }
  { _id : 2 , data : [4,5,6] }
  { _id : 3 , data : [6,7,8] }
  </code></pre>
  
  <p>I want to union the <code>data</code> array from two or more documents. </p>
  
  <p>The query I am using to find the union of <code>data</code> array of <code>id</code> 1 and 2 is: </p>
  
  <pre><code>db.coll.aggregate(
  {
      $match : {
          _id: { $in: [1, 2] }
      }
  },
  {
      $group: { 
          _id: 0,
          s0: { $first: "$data"}, 
          s1: { $first: "$data"}
      }
  },
  {
      $project: {
          _id: 0,
          ans: { $setUnion: [ "$s0","$s1"]}
      }
  }
  ).pretty()
  </code></pre>
  
  <p>But the query results in:</p>
  
  <pre><code>{7, 5, 0}
  </code></pre>
  
  <p>which seems to be the data of <code>id</code> 1 only.</p>
  
  <blockquote>
    <p>How to achieve the union between two or more documents on same array
    field?</p>
  </blockquote>
  
  <p><strong>PS: I'm using MongoDB 3.4</strong></p>