title: Updating a mongodb document with JSON object
body: <p>I want to update a MongoDB docment (using the Javascript db driver). I would like to pass in a JSON object and have that update the document ... something like:</p>
  
  <pre><code>Provider.prototype.updateProfile = function(username, profile, callback) {
    this.getCollection(function(error, profile_collection) {
      if( error ) callback( error );
      else {
        profile_collection.update(
          {username: username},
          {profile},
          function(error, profile){
            if( error ) callback(error);
            else callback(null, profile)
          });
      }
    });
  };
  </code></pre>
  
  <p>I want this to be a generic function, so that if the document structure changes I don`t have to re-write. At the moment I can only get this working by using </p>
  
  <pre><code>{"$set": {x:profile.x, y:profile.y}}
  </code></pre>
  
  <p>in the update, does anyone have a generic solutions so that I can pass in any profile:</p>
  
  <pre><code>profile = { .... }
  </code></pre>