2016-12-21 1 views
0

이 유성 서버 코드는 MongoDB의 수집을 업데이트하려고하지만, 제공에이 개 값을 업데이트 할 수 없습니다 오류 :몽고가 동시에

 let originalDoc = original.fetch()[0]; 
     Meteor.users.update(userId, { 
     $set: { 
      profile: originalDoc.profile, 
      cmpProfile: originalDoc.cmpProfile, 
      aaa: originalDoc.aaa 
     }, 
     $unset: { 
      'profile.abc': 1 
     } 
     }); 

오류 :

Exception while invoking method 'xyz' MongoError: Cannot update 'profile' and 'profile.abc' at the same time

어떤 아이디어? 들으

답변

0

오류가 꽤 자기 explainatory입니다 : 당신은 같은 시간 $set 전체 profile$unsetprofile.abc에서 MongoDB를 같은 작업을 수행 할 수 없습니다 수 없기 때문에. 대신 $unset를 호출

당신은 쿼리를 실행하기 전에 delete originalDoc.profile.abc;을 할 수있는 당신이 전체 포함 된 문서를 설정하는대로 그 효과적으로 profile에서 abc 필드를 제거합니다.

+0

delete originalDoc.profile.abc? $ unset originalDoc.profile.abc을 의미합니까? 그렇지 않은 경우 어떻게 삭제합니까? –

+0

'originalDoc.profile'을 전체적으로 설정하고 있습니다. 즉,'abc' 필드가 객체에 없으면 데이터베이스에 없을 것입니다. 효과적으로'abc' 필드를 두지 않으면 불필요한'$ unset'을 제거 할 수 있고 질의는 정상적으로 실행됩니다. – malarzm