title: How to update document in mongo with nested schema
body: <p>I have the following code:</p>
  
  <pre><code>add_new_patient : function(username,pname,pid,pdesc,callback){
                    var find_md = function(){
                        return function(err,pat){
                          if (err){
                           console.log('Error at adding patient: error at searching for users');
                           callback(2);//In the callback method I'm passing I have specific behavior for error handling for error codes.
                           return;
                          }
                          if (pat.lenth &gt; 0){
                              console.log('searching for md');
                              MD.find({'mdname':username},add_patient(pat));
                          }else{
                              console.log('Error at adding patient: no user found');
                              callback(-1);
                              return;
                         }
                    }}
  
                     var add_patient = function(pat){
                          return function(err,md){
                         if (err){
                             console.log('Error at adding patient: cannot find md');
                             callback(-1);
                             return;
                         }
                     callback(0);
                     }
                }
                console.log('searching for user '+pid);
                User.find({'name':pid},find_md());
  }
  </code></pre>
  
  <p>And these are my schemas:</p>
  
  <pre><code>var mdSchema = mongoose.Schema({
     mdname : String,
     pacients : [userSchema.ObjectId]
  });
  
  var userSchema =mongoose.Schema({
      name : String,
      password : String,
      phone : String,
      history : [{timestamp: Date , heart: Number }],
      md : {mdname: String, contact: Number}
  });
  </code></pre>
  
  <p>As you can guess from the code I want to add patients to the dms. First I search for the pid in the database. If I find a patient I start to look for mds. When I find the md I want to add the patient to the md. Now I don't know how to add them. The schema shows that I have an array of schemaUser, which is the type of patient, but I don't know how to append to it, not how to create an MD model from object from the data I received from the query. Also what should I insert into the array of patients? The _id of the found patient or the whole object? </p>