[SERVER-15266] $elemMatch/$all behavior in version 2.6.1 Created: 16/Sep/14  Updated: 18/Sep/14  Resolved: 18/Sep/14

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: 2.6.4, 2.7.5
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: krishna Assignee: David Storch
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to SERVER-13963 Different Results from nested array q... Closed
Operating System: ALL
Participants:

 Description   

I have created an db with the following structure

{
"_id" : ObjectId("54167c9a4420660b672d2a3f"),
"a" : "1111",
"pc" : [
    [
        "bb",
        "aa",
        {
            "c" : "cc",
            "d" : "dd"
        },
        {
            "c" : "aaa",
            "d" : "ddd"
        },
 
    ],
    [
        "cc",
        "dd",
        {
            "a" : "cc",
            "b" : "dd"
        },
        {
            "a" : "aaa",
            "b" : "ddd"
        },
                    }
     ]
  ]
}

and i have used the following query in mongodb version 2.4.6, it has given the correct output

 db.cg.find({'pc':{'$elemMatch':{'$all':['aa','bb']}}})

but the same query i have used in mongodb version 2.6.1 it is neither throwing any error nor giving any result



 Comments   
Comment by Ramon Fernandez Marina [ 18/Sep/14 ]

krishna114, this is a bug in 2.4 that was corrected in 2.6. MongoDB 2.6 does not recursively index nested arrays, and does not recursively traverse them in the matcher to look for nested array elements which match the query, so the behavior you're observing is expected.

This is consistent with the documentation for $all query operator.

Please see SERVER-13963 for a similar ticket containing more information.

Regards,
Ramón.

Comment by krishna [ 16/Sep/14 ]

hi @Ramon Fernandez , please find the following commands and try these in different versions
db.foo.insert({a: "1111",pc: [ [ "bb", "aa",

{ "c" : "cc", "d" : "dd"}

,

{ "c" : "aaa", "d" : "ddd" }

], [ "cc","dd",

{"a" : "cc","b" : "dd" }

,

{ "a" : "aaa", "b" : "ddd" }

] ]})
db.cg.find({'pc':{'$elemMatch':

{'$all':['aa','bb']}

}})

Comment by Ramon Fernandez Marina [ 16/Sep/14 ]

krishna114, thanks for your report, I'm able to reproduce the behavior you describe with the following code:

db.foo.drop()
db.foo.insert({_id : 1, x : [ [ "a", "b"],[ "c", "d"]]})
db.foo.insert({_id : 2, x : [ [ "e", "f"],[ "g", "h"]]})
db.foo.find({x:{$elemMatch:{$all:["a","b"]}}})

I can also confirm that the behavior in the 2.4 series is different. This could be a corner case of SERVER-13677.

Generated at Thu Feb 08 03:37:30 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.