[SERVER-6614] When matching multiple items in inner collections / document arrays, selecting with { 'innerCollection.$' : 1 } only returns the lastest of the matched element. Created: 26/Jul/12  Updated: 11/Jan/23  Resolved: 21/Aug/12

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: 2.2.0-rc0
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Gabriel Lesperance Assignee: Ben Becker
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-1013 positional $ operator field mismatch Closed
Operating System: ALL
Participants:

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

.



 Comments   
Comment by Githook User [ 11/Jan/23 ]

(Sorry for this wrong commit message posted here. Server ticket attached to this commit message is wrong. Please refer SERVER-66146 for "Make in-memory changes to system.views collection transactional.")

Author: {'name': 'Suganthi Mani', 'email': 'suganthi.mani@mongodb.com', 'username': 'smani87'}

Message: SERVER-6614 Make in-memory changes to system.views collection transactional.
Branch: master
https://github.com/mongodb/mongo/commit/bf9163b47cbaf51332374d559d2c0a46f7f1098a

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