title: Update/replaceAll deeply nested embedded data in MongoDB
body: <p>If I have the following fictive collection (could also be threaded comments) with nested embedded data:</p>
  <pre><code>db.likes.insertMany([
     { _id: 1, name: &quot;userNameA&quot; },
     { _id: 2, name: &quot;userNameB&quot;, likes: [
        { _id: 4, name: &quot;userNameA&quot; },
        { _id: 5, name: &quot;userNameB&quot; },
        { _id: 6, name: &quot;userNameA&quot;, likes: [
           { _id: 7, name: &quot;userNameB&quot; },
           { _id: 8, name: &quot;userNameA&quot;, likes: [
              { _id: 9, name: &quot;userNameB&quot; },
              { _id: 10, name: &quot;userNameA&quot; },
           ] },
        ] },
     ] },
     { _id: 3, name: &quot;userNameC&quot; }
  ])
  
  </code></pre>
  <p>If fore instance <code>userNameB</code> wants to update his user name, is there a way to <code>replaceAll</code> occurrences in the nested collection? (Without having specific logic iterating through each of the possible sub arrays with likes). Something this for deeply nested data:</p>
  <pre><code>db.likes.aggregate([
     {
       $project:
        {
           item: { $replaceAll: { input: &quot;$item&quot;, find: &quot;userNameB&quot;, replacement: &quot;newUserNameB&quot; } }
        }
     }
  ])
  </code></pre>