MongoWriteConcernException. the (immutable) field '_id' was found to have been altered to _id MongoWriteConcernException. the (immutable) field '_id' was found to have been altered to _id codeigniter codeigniter

MongoWriteConcernException. the (immutable) field '_id' was found to have been altered to _id


You cannot update the _id field.

Notice that your $userdata object variable contains the _id field and then you proceed to pass that $userdata object as the value to be updated. As a result, you are attempting to update the _id field.

You need to remove the _id from $userdata when doing '$set'=>$userdata.

$collection->update(array('_id'=>new MongoId($id)),array('$set'=>$userdata),array('upsert'=>FALSE));