How can I insert a new value in MongoDb Column Array?
// Connect Collection
$collection = $this->mongo_db->db->selectCollection('test');
// Remove All Document
$collection->remove();
// initially Insert abcd Column inside Firstnam Lastname Value
$test=array('abcd'=>
array("firstname" => "Bob", "lastname" => "Jones" )
);
// Insert Value
$content=$collection->insert($test);
// get 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"
}
}
// But Need Expect Result
{
"_id" : ObjectId("55995b0be5ffc4980b000041"),
"abcd" : {
"firstname" => "Bob",
"lastname" => "Jones" ,
"city" : "Tiruppur"
}
}
// Please be help to Find Solution