title: How to perform a bidirectional upsert in ArangoDB
body: <p>I'm working with a dataset similar to ArangoDB official <a href="https://www.arangodb.com/docs/stable/aql/examples.html#example-data" rel="nofollow noreferrer">&quot;friendship&quot; example</a>, except I'm adding a &quot;weight&quot; concept on the Edge Collection. Like so :</p>
  <p><strong>People</strong></p>
  <pre><code>[
    { &quot;_id&quot;: &quot;people/100&quot;, &quot;_key&quot;: &quot;100&quot;, &quot;name&quot;: &quot;John&quot; },
    { &quot;_id&quot;: &quot;people/101&quot;, &quot;_key&quot;: &quot;101&quot;, &quot;name&quot;: &quot;Fred&quot; },
    { &quot;_id&quot;: &quot;people/102&quot;, &quot;_key&quot;: &quot;102&quot;, &quot;name&quot;: &quot;Jacob&quot; },
    { &quot;_id&quot;: &quot;people/103&quot;, &quot;_key&quot;: &quot;103&quot;, &quot;name&quot;: &quot;Ethan&quot; }
  ]
  </code></pre>
  <p><strong>Friendship</strong></p>
  <pre><code>[
    { &quot;_from&quot;: &quot;people/100&quot;, &quot;_to&quot;: &quot;people/101&quot;, &quot;weight&quot;: 27 },
    { &quot;_from&quot;: &quot;people/103&quot;, &quot;_to&quot;: &quot;people/102&quot;, &quot;weight&quot;: 31 },
    { &quot;_from&quot;: &quot;people/102&quot;, &quot;_to&quot;: &quot;people/100&quot;, &quot;weight&quot;: 12 },
    { &quot;_from&quot;: &quot;people/101&quot;, &quot;_to&quot;: &quot;people/103&quot;, &quot;weight&quot;: 56 }
  ]
  </code></pre>
  <p>I want to write a function that, when someone interacts with someone else, UPSERTs the Friendship between the two (incrementing the weight by 1 if it existed before, or initializing with a weight of 1 if it's new).</p>
  <p>The trouble is, when executing that function, I have now clue on which direction the friendship was initialized, thus I cannot really use an upsert. So 2 questions here :</p>
  <ol>
  <li>Is there any way to make an upsert on an edge with &quot;bidirectional&quot; filter ?</li>
  </ol>
  <p>Like so, but bidirectional</p>
  <pre><code>UPSERT {
    // HERE, I BASICALLY WAN'T TO IGNORE THE SIDE
    _from: ${people1}, _to: ${people2}
  }
  INSERT {
    _from: ${people1}, _to: ${people2}, weight: 1
  }
  UPDATE {
    weight: OLD.weight + 1
  }
  IN ${friendshipCollection}
  RETURN NEW 
  </code></pre>
  <ol start="2">
  <li>Instead of trying to &quot;select the friendship, no matter the direction&quot;; should I rather actually duplicate the friendship on both directions (and constantly maintain / update it) ?</li>
  </ol>