title: Updating a particular sub document in mongo db php
body: <p>I have a collection in mongo db called EmployeeTbl with document like</p>
  
  <pre><code>{
  "_id": ObjectId("5a8d47d8d2ccda11fc004d91"),
  "EmployeeNumber": "9883456787",
  "FirstName": "Sana",
   ...
    "ContactDetails": [
   {
     "ContactTypeId": "04596c6f-82e6-8f00-e3a9-1f3199894284",
     "ContactType": "Phone",
     "ContactTypeValue": "99456789756" 
  },
   {
     "ContactTypeId": "71d0152c-293f-4c6f-2360-bbdfe368eacb",
     "ContactType": "Phone",
     "ContactTypeValue": "9894567890" 
    } 
   ] 
  </code></pre>
  
  <p>}</p>
  
  <p>I am trying to update a sub document inside ContactDetails and I have written below code. It is not updating the existing one. Instead of updating, it adds new sub document. 
  Please help me !!!</p>
  
  <pre><code>     public function updateContactDetailsForItsSubDocument()
  {
               // $bulkbatch = new MongoDB\Driver\BulkWrite(['ordered' =&gt; true]);  
  
                $subDocumentContactDetails = array(
                              "ContactDetails" =&gt; 
                                        array(
                                        "ContactType" =&gt; $this-&gt;ContactType,
                                        "ContactTypeValue" =&gt; $this-&gt;ContactTypeValue
                                     )
                                 );
  
                $this-&gt;collection-&gt;update(
                              array('_id' =&gt; new MongoDB\BSON\ObjectID($this-&gt;id), 'ContactDetails.ContactTypeId'=&gt; $this-&gt;ContactTypeId),
                              array('$set' =&gt; $subDocumentContactDetails)
                                  );
  
               // $this-&gt;manager-&gt;executeBulkWrite($this-&gt;collection, $bulkbatch);  
  
  }
  </code></pre>