[SERVER-42307] $lookup overwrites the entire object and erases fields (other than what "as" holds) when used inside an array of nested objects Created: 19/Jul/19  Updated: 19/Jul/19  Resolved: 19/Jul/19

Status: Closed
Project: Core Server
Component/s: Aggregation Framework
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Mert Hasret Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: Bug
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-42306 $lookup with an array of sub objects ... Backlog
Operating System: ALL
Steps To Reproduce:
  • Create a schema as shown in the "Description" section. 
  • Run the query given in the "Description" section on one of the versions listed in "Affects Version/s" section.
  • PS: My assumption is that the given aggregation doesn't give the expected output past 3.4.5, but I have only listed the version that I have tested the aggregation on.
Participants:

 Description   

Schema:
{
x:

{type: String, required: true}

,
a: [{
_b:

{type: Schema.Types.ObjectId, ref: "B", required: true}

,
c:

{type: Number, required: true}

,
_d:

{type: Schema.Types.ObjectId, ref: "D", required: true}

,
e: {
f:

{type: Number, required: true}

}
}]
}

lookup stage:
{
"$lookup":

{ from: "B", localField: "a._b", foreignField: "_id", as: "a._b" }

},
{
"$unwind":

{ path: "$a._b" }

}

expected result:
{
x:/.../,
a:{
_b:[Object],
c:/.../,
_d:/.../,
e:

{ f:/.../ }

}
}

result:
{
x:/.../,
a:

{ _b: [Object] }

,
}

As you can see above, fields inside the "a" gets overwritten by the $lookup operation.



 Comments   
Comment by Danny Hatcher (Inactive) [ 19/Jul/19 ]

Closing as duplicate of SERVER-42306.

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