2016-11-15 74 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;