Note that there are some explanatory texts on larger screens.

plurals
  1. POMongoDB pull element from array two levels deep
    text
    copied!<p>I have a collection with the following items :</p> <pre><code>{ "Queries" : [ { "Results" : [ { "id" : 1 }, { "id" : 2 } ] } ], "_id" : ObjectId("51ddb6f9b18996be485cba6f") } { "Queries" : [ { "Results" : [ { "id" : 0 }, { "id" : 3 } ] } ], "_id" : ObjectId("51ddb701b18996be485cba70") } { "Queries" : [ { "Results" : [ { "id" : 1 }, { "id" : 2 } ] } ], "_id" : ObjectId("51ddb705b18996be485cba71") } { "Queries" : [ { "Results" : [ { "id" : 1 }, { "id" : 2 }, { "id" : 4 } ] } ], "_id" : ObjectId("51ddb70db18996be485cba72") } { "Queries" : [ { "Results" : [ { "id" : 1 }, { "id" : 2 }, { "id" : null } ] } ], "_id" : ObjectId("51ddb7e4b18996be485cba73") } </code></pre> <p>The "Queries" field on my documents contains an array of subdocuments. These subdocuments contain an array of another subdocument.</p> <p>I want to remove all entries in the "Results" field where the documents "id" field is 1.</p> <p>I tried the following without success :</p> <pre><code>update({}, {$pull :{"Queries.Results": {"id":1}}}, {"multi":true}) update({}, {$pull :{"Queries.Results.id":1}}, {"multi":true}) </code></pre> <p>How would I achieve this in MongoDB?</p> <p>EDIT: Here is the expected result of find() after the update</p> <pre><code>{ "Queries" : [ { "Results" : [ { "id" : 2 } ] } ], "_id" : ObjectId("51ddb6f9b18996be485cba6f") } { "Queries" : [ { "Results" : [ { "id" : 0 }, { "id" : 3 } ] } ], "_id" : ObjectId("51ddb701b18996be485cba70") } { "Queries" : [ { "Results" : [ { "id" : 2 } ] } ], "_id" : ObjectId("51ddb705b18996be485cba71") } { "Queries" : [ { "Results" : [ { "id" : 2 }, { "id" : 4 } ] } ], "_id" : ObjectId("51ddb70db18996be485cba72") } { "Queries" : [ { "Results" : [ { "id" : 2 }, { "id" : null } ] } ], "_id" : ObjectId("51ddb7e4b18996be485cba73") } </code></pre>
 

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