2017-09-04 167 views
0

在PHP中使用MongoDB,在运行更新后让文档T1包含T1_MODULE和T2_MODULE的正确方法是什么?这样做会导致删除了T1_MODULE的工具> T1> T2_MODULE。更新子文档MongoDB

$updater['tools']['T1']['T2_MODULE']=$update_array; 
$this->db->user->updateOne(array("_id"=>$id),array('$set'=>$updater)); 

{ 
    "_id" : ObjectId("59a674bfa5cecc20bd660d43"),  
    "something" : [ 
     { 
      "else" : NumberInt(1) 
     } 
    ], 
    "another_thing" : {   
     "further_disclosure" : "" 
    }, 
    "tools" : { 
     "T1" : { 
      "T1_MODULE" : { 
       "a" : "x", 
       "b" : "y" 
      } 
     } 
    } 
} 

回答

0

答案 - 用点符号来代替:

$updater['tools.T1.T2_MODULE']=$update_array;