2012-07-16 2 views
1

레코드를 업데이트하는 중에 문제가 있습니다.몽고 (mongodb) 오브젝트의 일부분을 늘리십시오.

"_id" : "1141825507009", 
    "person" : [ 
     { 
      "amount" : 25, 
      "id" : "1141825507009" 
     } 
] 

person.id가 쉽게 1141825507009. 어디가 3으로 person.amount을 증가 할 : 내 문서 구조는 다음과 같은 것입니다. 대해 무엇을 :

Increment person.amount by 3 if person.id exist. 
Add to person list with amount 3 and id 239something845 if person.id does not exist in list. 
+0

은 두 개의 별도의 작업 또는 단일 중/또는 조치? –

+0

어떤 드라이버를 사용하고 있습니까? – Aaron

+0

@ BryceAtNetwork23 PHP 드라이버를 사용하고 있습니다. 하나의 액션에서 다음과 같이하고 싶습니다 : addtoset 대신에 set value를 증가 시키십시오. – ewooycom

답변

0

나는 당신이 원하는 것은 https://jira.mongodb.org/browse/SERVER-340 생각합니다. 보거나 투표하고 싶을 수도 있습니다. 당신이 원자 그것을 할 필요가없는 경우

, 당신은 같은 일을 할 수있는 :

db.foo.update({"person.id" : {$exists : false}, /* other criteria */}, 
    {$inc : {"person.amount":3}}); 
var result = db.runCommand({getLastError:1}) 
if (result.n == 0) { // nothing updated, person.id must exist 
    db.foo.update({/* criteria */}, 
     {$addToSet : {person : {amount:3, id:"239something845"}}}); 
} 
+0

아직 구현되지 않았습니다. 감사! – ewooycom

관련 문제