0

我在 mongoDb 中有一个集合。它类似于以下内容。

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。所以我用

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

结果 Education.content.1 变为空。但我希望 Education.content.1 被删除不为空。

如果有人知道解决方案,请帮助我。提前致谢。

4

1 回答 1

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)));
于 2012-11-28T07:35:14.770 回答