title: MongoWriteConcernException. the (immutable) field '_id' was found to have been altered to _id
body: <p>While making update in MongoDB in CodeIgniter I have the following error:</p>
  
  <pre><code>Type: MongoWriteConcernException
  
  Message: localhost:27017: After applying the update to the document {_id: ObjectId('55ee98543bd7af780b000029') , ...}, the (immutable) field '_id' was found to have been altered to _id: "55ee98543bd7af780b000029"
  
  Filename: C:\xampp\htdocs\CI\application\models\mongo_model.php
  </code></pre>
  
  <p>Here is my controller code</p>
  
  <pre><code>public function  update()
  {
      $userdata['firstname'] = $this-&gt;input-&gt;post('txtfirstname');
      $userdata['lastname'] = $this-&gt;input-&gt;post('txtlastname');
      $userdata['email'] =  $this-&gt;input-&gt;post('txtemail');
      $userdata['password'] = md5($this-&gt;input-&gt;post('txtpassword'));
      $userdata['_id'] = $this-&gt;input-&gt;post('hiddenId');
      $collection=  $this-&gt;mongo_model-&gt;updateuserdb($userdata);
      if ($collection)
      {
          header('location:'.base_url()."index.php/user".$this-&gt;index());
      }
  }
  </code></pre>
  
  <p>and model code is  </p>
  
  <pre><code>public function updateuserdb($userdata)
  {
      $id = $userdata['_id'];
      $collection = $this-&gt;mongo_db-&gt;db-&gt;selectCollection('myfirstCollection');
      $query = $collection-&gt;update(array('_id' =&gt; new MongoId($id)), array('$set' =&gt; $userdata), array('upsert' =&gt; FALSE));
      return $query;
  }
  </code></pre>