php - Append new value to array column -


how can insert new value in mongodb column array?

     // connect collection     $collection = $this->mongo_db->db->selectcollection('test');
// remove document $collection->remove(); // insert abcd column inside firstnam lastname value $test=array('abcd'=> array("firstname" => "bob", "lastname" => "jones" ) );
// insert value $content=$collection->insert($test);
// last insert id $newdocid = $test['_id'];
// append new value in above abcd array field column $newdata = array('$set'=> array('abcd'=> array('city'=>"tiruppur")) );
$collection->update(array("_id" => new mongoid($newdocid)), $newdata);

     // current result                 {                     "_id" : objectid("55995b0be5ffc4980b000041"),                     "abcd" : {                         "city" : "tiruppur"                     }                 }
// need expect result
{ "_id" : objectid("55995b0be5ffc4980b000041"), "abcd" : { "firstname" => "bob", "lastname" => "jones" , "city" : "tiruppur" } }
// please find solution

use dot notation:

$newdata = array('$set' => array('abcd.city' => "tiruppur")); 

Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -