title: How to merge array using UPSERT?
body: <p>I want to merge result from 3 collections into single collection but I can't merge finishedStatus attribute of final result.</p>
  
  <p>The final result collection:</p>
  
  <ul>
  <li>contains only unique status</li>
  <li>each document can keep the machine that make this status</li>
  <li>merge finishedStatus and then sum finishedStatus.count</li>
  <li>(Optional) sort finishedStatus[*].status </li>
  </ul>
  
  <p>Given</p>
  
  <p><strong>Collection A</strong></p>
  
  <pre><code> {"status": ["1","2","3"], "machine": "A", "finishedStatus": [{"status": "4", "count": 10}, {"status": "5", "count": 1}]}
   {"status": ["4","5","6"], "machine": "A", "finishedStatus": [{"status": "3", "count": 5}, {"status": "5", "count": 11}]}
  </code></pre>
  
  <p><strong>Collection B</strong></p>
  
  <pre><code>{"status": ["1","2","3"], "machine": "B", "finishedStatus": [{"status": "1", "count": 3}, {"status": "5", "count": 14}]}
  {"status": ["2","5","2"], "machine": "B", "finishedStatus": [{"status": "5", "count": 5}, {"status": "3", "count": 5}]}
  </code></pre>
  
  <p><strong>Collection C</strong></p>
  
  <pre><code>{"status": ["2","5","2"], "machine": "C", "finishedStatus": [{"status": "5", "count": 2}, {"status": "3", "count": 5}]}
  {"status": ["3","2","1"], "machine": "C", "finishedStatus": [{"status": "2", "count": 6}, {"status": "4", "count": 7}]}
  </code></pre>
  
  <p><strong>Collection result</strong></p>
  
  <pre><code>{"status": ["1","2","3"], "machine": ["A", "B"] , "finishedStatus": [{"status": "1", "count": 3}, {"status": "4", "count": 10}, {"status": "5", "count": 15}]}
  {"status": ["2","5","2"], "machine": ["B", "C"], "finishedStatus": [{"status": "5", "count": 7}, {"status": "3", "count": 10}]}
  {"status": ["3","2","1"], "machine": ["C"], "finishedStatus": [{"status": "2", "count": 6}, {"status": "4", "count": 7}]}
  {"status": ["4","5","6"], "machine": ["A"], "finishedStatus": [{"status": "3", "count": 5}, {"status": "5", "count": 11}]}
  </code></pre>
  
  <p>How to write AQL INSERT/UPDATE/UPSERT to make the final result?</p>
  
  <p>This is my AQL</p>
  
  <pre><code>FOR doc IN A
  UPSERT {"status": doc.status}
  INSERT {"status": doc.status, "machine": [doc.machine], "finishedStatus": doc.finishedStatus}
  UPDATE {
    "machine": APPEND(OLD.machine, doc.machine, true),
    "finishedStatus": &lt;-- I cannot write AQL to update finishedStatus
       How to write AQL to update this property?
  }
  IN result
  </code></pre>
  
  <p>Thank you</p>