title: Updating a subdocument within another subdocument
body: <p>My app is an API build with Expressjs / Mongoose...</p>
  
  <p>I have the following Schema, which I am trying to update a subdocument of a subdocument. Essentially the "phones" array, which is part of the "contacts" array, which is a subdocument of the "profile" object.</p>
  
  <p>I'm trying to understand how to traverse through an object tree and update.</p>
  
  <p>Here is an example schema that I'm using:</p>
  
  <pre><code>{
     "_id": "588b5a7d6d76c815ff6b9e7a",
     "name": "Joe Smith",
     "owner_id": "588b5a5d6d76c815ff6b9e79",
     "__v": 1,
     "contacts": [
        {
           "contact_name": "Jim Parks",
           "_id": "588b5abd6d76c815ff6b9e7c",
           "phones": []
        },
        {
           "contact_name": "Perry Mips",
           "_id": "588b5abd6d76c815ff6b31de",
           "phones": []
        }
     ]
  }
  </code></pre>
  
  <p>I tried to fist narrow the search by doing a findOn() and passing the ownerId for the record. Then updating the "contacts" array in the following way:</p>
  
  <pre><code>router.route('/:ownerId/addphone/:contactId')
  .put(function(req, res) {
  
    console.log('Req Body: ', req.body);
    console.log('Req: ', req.params);
    Profile.findOne({owner_id:req.params.ownerId}, function(err, profile) {
  
      var contacts = req.body.contacts;
      console.log('contacts', contacts);
  
      profile.contacts.id(req.body._id) = contacts;
      profile.save();
  
    });
  });
  </code></pre>
  
  <p>But this doesn't seem to work.</p>
  
  <p>Any help would be great!</p>