Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-11740

cannot do $elemMatch query on array index field in mongodb 2.4

    • Type: Icon: Bug Bug
    • Resolution: Won't Fix
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.4.9
    • Component/s: Querying
    • Environment:
    • ALL
    • Hide

      2.4.9-pre-

      > db.c.insert({a:[[{b:3}]]})
      > db.c.find({"a.0":{$elemMatch:{b:3}}})
      > // nothing was returned
      

      2.5.4-pre-

      > db.c.insert({a:[[{b:3}]]})
      > db.c.find({"a.0":{$elemMatch:{b:3}}})
      { "_id" : ObjectId("5286b36c89a3f0da8275dca9"), "a" : [  [  {  "b" : 3 } ] ] }
      
      Show
      2.4.9-pre- > db.c.insert({a:[[{b:3}]]}) > db.c.find({ "a.0" :{$elemMatch:{b:3}}}) > // nothing was returned 2.5.4-pre- > db.c.insert({a:[[{b:3}]]}) > db.c.find({ "a.0" :{$elemMatch:{b:3}}}) { "_id" : ObjectId( "5286b36c89a3f0da8275dca9" ), "a" : [ [ { "b" : 3 } ] ] }

      Query behavior discrepancy: In version 2.4 of MongoDB, there's no support for doing an $elemMatch on an index of an array field. This is supported in 2.5, however. Intuitively, the 2.5 behavior seems correct, which could mean 2.4 should be updated or this change in behavior should have some documentation (and this ticket can be moved to DOCS).

            Assignee:
            Unassigned Unassigned
            Reporter:
            luke.lovett Luke Lovett
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: