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

When matching multiple items in inner collections / document arrays, selecting with { 'innerCollection.$' : 1 } only returns the lastest of the matched element.

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.2.0-rc0
    • Component/s: Querying
    • None
    • ALL

      When matching multiple items in inner collections / document arrays, selecting with

      { 'innerCollection.$' : 1 }

      only returns one of the matched element.

      e.g.:
      Doing

      > db.testCollection.insert({ name : 'Albert', innerCollection : [

      {memberId: 'red'}

      ,

      {memberId : 'green'}

      ] })
      > db.testCollection.insert({ name : 'Beatrice', innerCollection : [

      {memberId: 'red'}

      ,

      {memberId : 'blue'}

      ] })
      > db.testCollection.insert({ name : 'Carl', innerCollection : [

      {memberId: 'green'}

      ,

      {memberId : 'blue'}

      ] })

      > db.testCollection.find({ $and : [

      {'innerCollection.memberId' : 'blue'}

      ,

      {'innerCollection.memberId' : 'red'}

      ]},

      {'innerCollection.$' : 1}

      )
      { "_id" : ObjectId("5011c44a5748f01ae71d50d7"), "innerCollection" : [

      { "memberId" : "red" }

      ] }

      properly finds the requested documents, but the innerCollection item only returns the element matching

      { 'innerCollection.memberId' : 'red' }

      .

            Assignee:
            benjamin.becker Ben Becker
            Reporter:
            glesperance Gabriel Lesperance
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: