Alexandru Olaru
Alexandru Olaru

Reputation: 7092

How to unset a field from all documents with php mongo adapter?

I have the task to $unset some fields from a collection, what i am trying to do :

     $collection->update(
            array(
                'field' => array('$exists' => true),
            ),
            array(
                '$unset' => array(
                    'field' => '',
                )
            ),
            array(
                'multi' => true
            )
        );

In xdebug i am getting: $collection: {w => 1, wtimeout => 10000} but when i check database nothing was changed my field is there untouched.

Upvotes: 0

Views: 2428

Answers (1)

Alexandru Olaru
Alexandru Olaru

Reputation: 7092

Found the issue: Actually the parameter for multi in php is multiple, i didn't count the responses and didn't see that it was unset-ing just one document.

 $collection->update(
        array(
            'field' => array('$exists' => true),
        ),
        array(
            '$unset' => array(
                'field' => '',
            )
        ),
        array(
            'multiple' => true
        )
    );

Upvotes: 4

Related Questions