title: MongoDB remove an item from an array inside an array of objects
body: <p>I have a document that looks like this:</p>
  
  <pre><code>{
    "_id" : ObjectId("56fea43a571332cc97e06d9c"),
    "sections" : [
      {
        "_id" : ObjectId("56fea43a571332cc97e06d9e"),
        "registered" : [
          "123",
          "e3d65a4e-2552-4995-ac5a-3c5180258d87"
        ]
      }
    ]
  }
  </code></pre>
  
  <p>I'd like to remove the <code>'e3d65a4e-2552-4995-ac5a-3c5180258d87'</code> in the <code>registered</code> array of <em>only</em> the specific section with the <code>_id</code> of <code>'56fea43a571332cc97e06d9e'</code>. </p>
  
  <p>My current attempt is something like this, but it just returns the original document unmodified.</p>
  
  <pre><code>db.test.findOneAndUpdate(
  {
    $and: [
      {'sections._id': ObjectId('56fea43a571332cc97e06d9e')},
      {'sections.registered': 'e3d65a4e-2552-4995-ac5a-3c5180258d87'}
    ]
  },
  {
    $pull: {
      $and: [
        {'sections._id': ObjectId('56fea43a571332cc97e06d9e')},
        {'sections.registered': 'e3d65a4e-2552-4995-ac5a-3c5180258d87'}
      ]
    }
  })
  </code></pre>
  
  <p>I've looked in to <code>$pull</code>, but I can't seem to figure out how to make it work on an array of nested objects containing another array. The <code>$pull</code> examples all seem to deal with only one level of nesting. How do I remove the matching entry from the <code>registered</code> array of the item in the <code>sections</code> array with the <code>_id</code> that I supply?</p>