繁体   English   中英

PHP / MongoDB,无法更新集合中的记录

[英]PHP/MongoDB, Unable to update records in a collection

我正在尝试使用php codeigniter更新mongodb中的记录,但我无法这样做。

我的控制器类:

function updatetodb_post(){

$updateddata = array('$set' => array("lang" => "English"));

$this->load->model('data_model');

$uid    = 1;

$this->data_model->updaterecords($uid, $updateddata);

}

我的模特班:

function updaterecords($uid, $updatedata){
    $this->load->library('mongo_db'); 

    $recoundsbyuid = $this->mongo_db->get_where($this->_testcollectoin, array("uid" => $uid));

    $this->mongo_db->update($this->_testcollectoin, $recoundsbyuid, $updatedata);

}

我要在collectoin中更新的数据:

$data = array(
                  "uid" => "1",
                  "type" => "Movie",
                  "genre" => "Action"
                  );

_testcollectoinis我的收藏名称。 我想在数组中再添加一个字段( lang )。

我们可以使用以下命令更新给定数据

$this->mongo_db->where(array("uid" => $uid))->set($updatedata)->update($this->_testcollectoin);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM