title: Updating nested object in mongoose
body: <p>I have searched many questions on nested objects, but all I found where related to array[s].</p>
  
  <p>I am looking for a updating simple nested object in mongoose.</p>
  
  <p>From here <a href="http://mongoosejs.com/docs/guide.html" rel="noreferrer">http://mongoosejs.com/docs/guide.html</a></p>
  
  <pre><code>there is an example schema :
  var blogSchema = new Schema({
    title:  String,
    author: String,
    body:   String,
    comments: [{ body: String, date: Date }],
    date: { type: Date, default: Date.now },
    hidden: Boolean,
    meta: {
      votes: Number,
      favs:  Number
    }
  });
  </code></pre>
  
  <p>Once created a document,</p>
  
  <p>How can I change the favs number later on?</p>
  
  <p>There is no document for the same that I could find.</p>
  
  <p>This is what I did:</p>
  
  <pre><code>blog.findById(entityId, function(err, mainDoc){
        if(err || !mainDoc) return next(err || 'Document not found');
        var subDoc = mainDoc['meta'];
        if(subDoc){
          subDoc = _.extend(subDoc, { favs : 56 }); //_ lib already available
          console.log(mainDoc.get('meta')); //Prints the updated result with favs = 56  OK
          mainDoc.save(function(err, doc){
             console.log(doc.get('meta')); // prints the updated results with favs = 56 OK
          });
        } else next('Not found');
      });
  </code></pre>
  
  <p>Everything works file and all console gives the desired result.</p>
  
  <p>But when I switch to mongoose console and query the document, I do not get the updated result.</p>
  
  <p>I know there can be other ways to achieve the same, but I am only looking for what I am doing wrong in this particular code.</p>
  
  <p>Why the console, after saving document, gives unmatched data from database?</p>
  
  <p>Upon enabling the mongoose debug option, I found the in query there is no such data to be updated. Query fires with blank $set. { $set : {} }</p>