更新在使用代码点火器的 mongo 数据库中不起作用


Update not working in mongo db using codeigniter

这是我的控制器:

$key['conversation_id']=1;
$update_data['is_read']=0;
$getupdate = $this->Common_model->update_msg($key,$update_data);

这是我的模型

function update_msg($updatekey, $updatevalue) {
    $result = $this->mongo_db->db->messages->update($updatekey,array('$set'=> $updatevalue));
    return $result;
}

如果我尝试打印响应,那么我将得到以下结果

Array ( [updatedExisting] => 1 [n] => 1 [connectionId] => 10 [err] => [ok] => 1 ) 
    $converstion_id=1;
    $update_data=0;
    $getupdate = $this->Common_model->update_msg($converstion_id,$update_data);
//In Model
    function update_msg($converstion_id, $update_data)
    {
        $result = $this->mongo_db->db->messages->update(array("converstion_id"=>$converstion_id),array('$set'=>array("is_read"=>$update_data)));
        return $result;
    }

试试这段代码。

$key['conversation_id']=1;
$update_data['is_read']=0;
$data_array['$set'] = $update_data;
$result = this->mongo_db->db->messages->update($key, $data_array);
return $result;