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.

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Duplicate
    • Affects Version/s: 2.2.0-rc0
    • Fix Version/s: None
    • Component/s: Querying
    • Labels:
      None
    • Operating System:
      ALL

      Description

      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' }

      .

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                Created:
                Updated:
                Resolved: