title: Correct way to do a PATCH upsert request
body: <p>What is the proper way to request the following upsert to a REST API?</p>
  <p>I'm struggling to structure a NoSQL collection, which is based on the most requested returns to the front-end application.</p>
  <p>Suppose you have the following document:</p>
  <pre><code>{
      'user' : {
          'private_comments': [
              //object available only to user 1
              { 
                  'id': 1,
                  'bar': 'He is very good',
                  '...': '...'
              },
              //object available only to user 2
              { 
                  'id': 2,
                  'bar': 'He is very bad',
                  '...': '...'
              }
          ],
          'public_comments': '' //infos available to all users
      } 
  }
  </code></pre>
  <p>It is needed to upsert an element to the user.private_comments array.</p>
  <p>According to <a href="https://www.rfc-editor.org/rfc/rfc6902#appendix-A.5" rel="nofollow noreferrer">https://www.rfc-editor.org/rfc/rfc6902#appendix-A.5</a>, I could request a replace instruction PATCHing the following data:</p>
  <pre><code>{ 'op': 'replace', 'path': '/user/comments/$index', 'value': 'Actually, he is OK'}
  </code></pre>
  <p>The problem is that '$index' is unknown in this case.</p>
  <p>A possible solution that I came up with was to create something like the following operation:</p>
  <pre><code>{ 'op': 'upsert', 'find_by': 'id', 'find': 1, 'path': '/user/comments', 'value': 'Nope, he really sucks' }
  </code></pre>
  <p>However, the user implementing the API should't provide the id value inside the PATCH request, because this value is already accessible via the receive token. Should I simplify the operation to:</p>
  <pre><code>{ 'op': 'upsert', 'path': '/user/comments', 'value': 'Nope, he really sucks' }
  </code></pre>
  <p>and treat it at the backend, so when it's and upsert operation without 'find' and 'find_by' variables I assume 'find_by': 'id' and 'find': value_from_token?</p>
  <p>Also, I cannot do a simple GET/UPDATE at the hole document because the user doesn't receive the hole document, so an update would compromise the data.</p>