[SERVER-1678] Query on a field of deep nested arrays and dictionaries don't find all document Created: 25/Aug/10  Updated: 07/Mar/14  Resolved: 31/Aug/10

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: 1.6.1
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: kosii Assignee: Mathias Stearn
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: File testcase.js    
Operating System: ALL
Participants:

 Description   

I've got this 3 document in a collection: http://pastie.org/1114659 , and I have these query objects:

{'fields.5.3.0': 31}

    (nº1)

{'fields.5.6.0': 31}

    (nº2)
The first two document differs only in the name of a key (I changed it from "3" to "6"), and the third is like the first only with one nested dictionary less.
Obviously, the query nº1 should match the 1st and the 3rd document, and the nº2 should match the 2nd document, but:
> db.bug.find(

{'fields.5.3.0': 31}

).count()
1
(instead of 2)
> db.bug.find(

{'fields.5.6.0': 31}

).count()
1
(it seems corrent)

Am I mistaking somewhere?



 Comments   
Comment by kosii [ 31/Aug/10 ]

Ok, thank you.

Comment by Mathias Stearn [ 28/Aug/10 ]

I think I found the cause. The issue is that for one of the objects it takes the '3' in your query to be an index into the array. Take a look at the output from these calls:

> db.foo.findOne(

{'fields.5.3.0': 31}

)._id
ObjectId("4c785f527b9830571f000002")
> db.foo.findOne(

{'fields.5.3.3.1.0': 31}

)._id
ObjectId("4c785f357b9830571f000000")
> db.foo.findOne(

{'fields.5.2.3.1.0': 31}

)._id
ObjectId("4c785f527b9830571f000002")

I think the best solution is not to mix numeric keys and arrays due to the ambiguity that they introduce.

Comment by kosii [ 25/Aug/10 ]

In the javascript file I've put 4 object in a collection (v, w, x, y). In order to get w and y objects, I respectively changed a field name from '3' to '6' in v and x object. I wrote two queries also (

{'fields.5.3.0': 31}

and

{'fields.5.6.0': 31}

), they are different only on the field name. The first query only matches one document , but the second query matches two (w and y), although there is't any difference but only in the field name.

Comment by Eliot Horowitz (Inactive) [ 25/Aug/10 ]

I only see 1 document that should match the first query.

If you think there is an error, please provide a .js file with the full example.

Generated at Thu Feb 08 02:57:43 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.