Yahorow Yahorow -4 years ago 183
PHP Question

How to delete fields from Mongodb (Mongo PHP)?

I tried to delete field from document in Mongo terminal like as:

db.getCollection('objects').update({}, {$unset: {'value.speed':''}} , {multi: true});

It works, but how to write this in Mongo PHP(old version).

I tried:

$find = [
'value' => ['$exists' => true]

$update = [];

$update['$unset']['value']['speed'] = null;

$this->collection->update($find, $update, ['multiple' => true]);

Answer Source

Your $update usage is incorrect. Try something like the following:

$update = [
    '$unset' => [        
        'value.speed' => true

See this or this post, or search for similar to understand better.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download