Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy $pull operator doesn't work on MongoDB when using empty criteria?
    primarykey
    data
    text
    <p>I have nodes like this:</p> <pre><code>[_id] =&gt; MongoId Object ( [$id] =&gt; 4e90cb3cd68417740c000017 ) [label] =&gt; mystery [owner] =&gt; me [parents] =&gt; Array ( [0] =&gt; Array ( [id] =&gt; MongoId Object ( [$id] =&gt; 4e8c6bb6d68417340e0004ca ) [owner] =&gt; userid [timestamp] =&gt; 1318112522 ) ) [timestamp] =&gt; 1318112060 [translabel] =&gt; mystery [type] =&gt; 0 </code></pre> <p>What I am trying to do is to remove parents with id : 4e8c6bb6d68417340e0004ca , wherever they are.</p> <p>For example this should have been working (latest Mongo):</p> <pre><code>db.nodes.update({},{$pull : {"parents": { "id" : ObjectId("4e8c6bb6d68417340e0004ca") }}}); </code></pre> <p>or equaly in PHP (latest driver etc):</p> <pre><code>$mongodb-&gt;nodes-&gt;update(array(),array('$pull'=&gt; array('parents'=&gt;array('id'=&gt; new MongoId("4e8c6bb6d68417340e0004ca"))))); </code></pre> <p>both don't do anything!</p> <hr> <p>on the other hand:</p> <pre><code>db.nodes.update({"_id": ObjectId("4e90cb3cd68417740c000017")},{$pull : {"parents": { "id" : ObjectId("4e8c6bb6d68417340e0004ca") }}}); </code></pre> <p>or equaly in PHP:</p> <pre><code>$mongodb-&gt;nodes-&gt;update(array('_id' =&gt; new MongoId("4e90cb3cd68417740c000017"),array('$pull'=&gt; array('parents'=&gt;array('id'=&gt; new MongoId("4e8c6bb6d68417340e0004ca"))))); </code></pre> <p>work perfectly well! Is this a bug? Is it a problem that I use "id" instead of "_id" with MongoID objects in my subdocuments? Thanks in advance for any help!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload