2016-11-15 76 views
0

这是我的控制器:更新不蒙戈工作DB使用笨

$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) 
+0

我不能提前更新蒙戈db.Thanks你的答案 –

回答

0
$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; 
    } 
+0

对不起[哈日(https://stackoverflow.com/users/4998427/hariharaprabu -m)在这里,我正在尝试更新“对话ID”而不是“ID”。但我试着用对话ID来代码,但它不接受mongoId。 但是,谢谢你的回应 –

+0

在这种情况下,删除新的mongo Id就是这样! –

0

试试这个代码..

$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;