Note that there are some explanatory texts on larger screens.

plurals
  1. POMongoDB nested array query
    primarykey
    data
    text
    <p>I've asked this as a comment on <a href="https://stackoverflow.com/questions/5250652/query-a-nested-array-in-mongodb" title="another">another</a> question, and also posted a <a href="https://groups.google.com/forum/#!searchin/mongodb-user/advertised/mongodb-user/SetYxmdvjTE/NiKGhu6cCKsJ" rel="noreferrer" title="question">question</a> on mongodb-user. No responses so far, so I'm resorting to asking a separate question. </p> <p>The <a href="http://docs.mongodb.org/manual/reference/operator/in/#op._S_in" rel="noreferrer" title="documentation">documentation</a> states:</p> <blockquote> <p>If the field holds an array, then the $in operator selects the documents whose field holds an array that contains at least one element that matches a value in the specified array (e.g. , , etc.)</p> </blockquote> <p>I'm using:</p> <pre><code>mongod --version: db version v2.2.2, pdfile version 4.5 Thu May 30 12:19:12 git version: d1b43b61a5308c4ad0679d34b262c5af9d664267 mongo --version: MongoDB shell version: 2.0.4 </code></pre> <p>In MongoDB shell:</p> <pre><code>db.nested.insert({'level1': {'level2': [['item00', 'item01'], ['item10', 'item11']]}}) </code></pre> <p>Here's a list of queries that should work according to the documentation, and the results they produce:</p> <p>Why doesn't this work?</p> <pre><code>&gt; db.nested.findOne({'level1.level2.0': 'item00'}) null </code></pre> <p>Why do I need the $all?</p> <pre><code>&gt; db.nested.findOne({'level1.level2.0': {'$all': ['item00']}}) { "_id" : ObjectId("51a7a4c0909dfd8872f52ed7"), "level1" : { "level2" : [ [ "item00", "item01" ], [ "item10", "item11" ] ] } } </code></pre> <p>At least one of the following should work, right?</p> <pre><code>&gt; db.nested.findOne({'level1.level2.0': {'$in': ['item00']}}) null &gt; db.nested.findOne({'level1.level2': {'$in': ['item00']}}) null </code></pre> <p>Any ideas? We're considering abandoning MongoDB if the query syntax doesn't work as advertised.</p> <p>Thanks!</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.
 

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