title: mongodb update on JSON array
body: <p>I have this data in Mongo:</p>
  
  <pre><code>{'_id':1,
               'name':'Root',
               'taskId':1,
               'parentId':"",
               'path':[1],
               'tasks':[  {"taskId":3,parentId:1,name:'A',type:'task'},
                          {"taskId":4,parentId:1,name:'D',type:'task'},
                          {"taskId":5,parentId:4,name:'B',type:'task'},
                          {'type':'project' , 'proRef':2},
                          {"taskId":6,parentId:3,name:'E',type:'task'},
                          {"taskId":7,parentId:6,name:'C',type:'task'}]
  
              }
  </code></pre>
  
  <p>Now I want to update taskId 6 with new Json data .</p>
  
  <pre><code>var jsonData = {"taskId":6,"name":'Sumeet','newField1':'Val1','newField2':'Val2'}
  </code></pre>
  
  <p>query should update if field is available else add new key to existing .Output Like</p>
  
  <pre><code>{"taskId":6,parentId:3,name:'Sumeet',type:'task','newField1':'Val1','newField2':'Val2'}]
  </code></pre>
  
  <p>I have tried few query but it is completely replacing json .</p>
  
  <pre><code> db.projectPlan.update({_id:1,'tasks.taskId':6},{$set :{'tasks.$':jsonData }});
  </code></pre>
  
  <p>Thanks in advance for your helps!
  Sumeet </p>