2012-11-28 4 views
0

mongoDb에 콜렉션이 있습니다. 그것은 다음과 유사합니다.mongo에서 중첩 된 요소의 인덱스 삭제

array(
    '_id' => new MongoId("50b35d1217ce10ac1000000f") 
    'Education' => 
     array (
     'content' => 
     array (
      '0' => 
      array (
      'Organization' => 'SUST', 
      'Degree' => 'BSC', 
      'Department' => '', 
      'Location' => 'Dhaka', 
      'Session' => '2 Years', 
     ), 
      '1' => 
      array (
      'Organization' => 'DU', 
      'Degree' => 'BSC', 
      'Department' => '', 
      'Location' => 'Dhaka', 
      'Session' => '2 Years', 
     )  
     ), 
     'sharing' => 'public', 
    ), 
) 

Education.content.1을 (를) 컬렉션에서 삭제하고 싶습니다. 그래서이 Education.content.1가 null로되는 결과로서

update(array('_id' => new MongoId('50b35d1217ce10ac1000000f')), array('$unset' => array('Education.content.1' => 1))); 

사용. 하지만 Education.content.1을 null이 아니게 삭제하려고합니다.

아무도 해결책을 알고 있다면 도와주세요. 미리 감사드립니다.

답변

1

사용 $pull$unset 후 :

update(array('_id' => new MongoId('50b35d1217ce10ac1000000f')), 
array('$unset' => array('Education.content.1' => 1))); 
update(array('_id' => new MongoId('50b35d1217ce10ac1000000f')), 
array('$pull' => array('Education.content' => null))); 
관련 문제