2013-03-04 2 views
0

나는이 구조가 :MongoDB에 포함 된 업데이트 객체

{ 
"_id": NumberInt(101), 
"link_id": { 
"125": { 
    "thumb_position": NumberInt(1), 
    "last_scan": NumberInt(1234563645), 
    "row_numb": NumberInt(301), 
    "clicks": NumberInt(120) 
    }, 
"126": { 
    "thumb_position": NumberInt(2), 
    "last_scan": NumberInt(-2147483648), 
    "row_numb": NumberInt(1301), 
    "clicks": NumberInt(199) 
    }, 
    { 
    ... 
    } 
} 
} 

을 나는 새 linkids와 문서를 업데이트하고 싶어 :

$value = array (
'130' => 
array (
    'thumb_position' => 1, 
    'last_scan' => 1234563640, 
    'row_numb' => 300, 
    'clicks' => 120, 
)); 
$update_status = $collection->update(array('_id'=>intval(101)), array('$set' => array('link_id' => $value)) , array("upsert"=>true ,"multiple"=> true , "safe"=> true)); 
: 나는 PHP에서 시도

{ 
"_id": NumberInt(101), 
"link_id": { 
    "125": { 
    "thumb_position": NumberInt(1), 
    "last_scan": NumberInt(1234563645), 
    "row_numb": NumberInt(301), 
    "clicks": NumberInt(120) 
}, 
"126": { 
    "thumb_position": NumberInt(2), 
    "last_scan": NumberInt(-2147483648), 
    "row_numb": NumberInt(1301), 
    "clicks": NumberInt(199) 
}, 
"127": { 
    "thumb_position": NumberInt(1), 
    "last_scan": NumberInt(-2147483628), 
    "row_numb": NumberInt(1304), 
    "clicks": NumberInt(195) 
} 
} 

하지만이 값은이 130으로 link_ids를 덮어 쓰는 것입니다.

임베디드 aproach ... 이것은 배열이 아니기 때문에, 그러나 객체, 이것을 해결하는 방법에 대한 아이디어? 정말 고마워. 대신

+0

당신이 배열을 사용하는 경우 발생 (=> 배열 ('link_id.130'=> $ 값을 '$ 세트'[ '130'])) 대신에? – nutlike

+0

너의 대답에 너의 뉘앙스. 나는이 시도하고 결과였다'code' { "_id"NumberInt (100), "LINK_ID": { "129": { "THUMB_POSITION"NumberInt (1), "last_scan"NumberInt (1,234,563,649) "row_numb"NumberInt (309) "클릭"NumberInt (129) } "130"널 } } \t 값이었다'code' $ value_i = 배열 ​​( 'thumb_position'=> 1, 'last_scan'=> 1234563641, 'row_numb'=> 301, 'clicks'=> 121, ); 그래서 그것은 null 입구를 추가했다. 길은 어림짐작이다. 다시 Thx. – rrubiorr81

+0

그것의 지금 일하는 .. .. '코드'$ value_i = array ('thumb_position'=> 1, 'last_scan'=> 1234563641, 'row_numb'=> 301, 'clicks'=> 121,); 하지만 'code'$ value [ '130'] ... 차이는 없습니다. – rrubiorr81

답변

1

시도 다음 코드를

$value = array (
    'thumb_position' => 1, 
    'last_scan' => 1234563640, 
    'row_numb' => 300, 
    'clicks' => 120, 
); 

$update_status = $collection->update(
    array('_id'=>intval(101)), 
    array('$set' => array('link_id.130' => $value)), 
    array("upsert"=>true ,"multiple"=> true , "safe"=> true) 
); 
관련 문제