title: Partial update of a subdocument with nodejs/mongoose
body: <p>Is it possible to set multiple properties on a (sub)document in one go with Mongoose? An example of what I'm trying to do:</p>
  
  <p>Let's say I have this schema:</p>
  
  <pre><code>var subSchema = new Schema({
      someField: String,
      someOtherField: String
  });
  
  var parentSchema = new Schema({
      fieldOne: String,
      subDocs: [subSchema]
  })
  </code></pre>
  
  <p>Then I would like to do:</p>
  
  <pre><code>exports.updateMyDocument = function(req, res) {
      var parentDoc = req.parentDoc; // The parent document. Set by parameter resolver.
      var document = req.myDoc; // Sub document of parent. Set by parameter resolver.
      var partialUpdate = req.body; // updated fields sent as json and parsed by body parser
      // I know that the statement below doesn't work, it's just an example of what I would like to do.
      // Updating only the fields supplied in "partialUpdate" on the document
      document.update(partialUpdate); 
      parentDoc.save(function(err) {
          if(err) {
              res.send(500);
              return;
          }
          res.send(204);
      }); 
  };
  </code></pre>
  
  <p>Normally, I could achieve this using the <code>$set</code> operator, but my problem is that <code>document</code> in this example is a subdocument (embedded schema) of <code>parentDoc</code>. So when I tried to do</p>
  
  <pre><code>Parent.update({_id: parentDoc._id, "subDocs._id": document._id}, 
      {$set: {"subDocs.$" : partialUpdate}}, 
      function(err, numAffected) {});
  </code></pre>
  
  <p>it replaced the subdocument instance identified by <code>subDocs._id</code>. Currently I have "solved" it by setting only fields manually, but I was hoping for a better way to do this.</p>