Php 将新值追加到数组列

Php 将新值追加到数组列,php,mongodb,Php,Mongodb,如何在MongoDb列数组中插入新值? // 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'

如何在MongoDb列数组中插入新值? // 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); //连接集合 $collection=$this->mongo_db->db->selectCollection('test')
//删除所有文档 $collection->remove(); //最初在Firstnam Lastname值内插入abcd列 $test=数组('abcd'=> 数组(“firstname”=>“Bob”,“lastname”=>“Jones”) );
//插入值 $content=$collection->insert($test)
//获取最后一个插入ID $newDocID=$test[''u id']
//在上述abcd数组字段列中追加新值 $newdata=数组(“$set”=> 数组('abcd'=>数组('city'=>“Tiruppur”)) );
$collection->update(数组(“_id”=>newmongoid($newDocID)),$newdata);
//当前结果 { “_id”:ObjectId(“55995b0be5ffc4980b000041”), “abcd”:{ “城市”:“蒂鲁珀” } }
//但需要预期的结果
{ “_id”:ObjectId(“55995b0be5ffc4980b000041”), “abcd”:{ “firstname”=>“Bob”, “姓氏”=>“琼斯”, “城市”:“蒂鲁珀” } }
//请帮助寻找解决方案 使用点符号:

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

感谢您提供的u r response TECHWISDOM,但此Ans是错误的,我已经尝试了此代码,但出现了错误:字段'abcd'必须是数组,但在文档{u id:ObjectId('559aa69ee5ffc4680c000043')中属于Object类型错误代码:16837@user1837631,我明白了。请查看我编辑的答案,并告诉我发生了什么。@user1837631,不客气,我的朋友。如果您能将此标记为答案(左边的V),我将非常高兴。谢谢
$newdata = array('$set' => array('abcd.city' => "Tiruppur"));