-
Type:
Improvement
-
Resolution: Unresolved
-
Priority:
Major - P3
-
None
-
Affects Version/s: None
-
Component/s: Aggregation Framework
-
Query Optimization
-
None
-
None
-
None
-
None
-
None
-
None
-
None
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"
}
}
Expected Output
{
x:/.../,
a:[{
_b:[Object],
c:/.../,
_d:/.../,
e:{
f:/.../
}
}]
}
Output
{
x:/.../,
a: {
_b: [Object]
}
}
As you can see above, fields inside the "a" gets overwritten by the $lookup operation, and the field called "a" turns into an object after the aggregation (just like in the behavior of the $unwind operator).
- is duplicated by
-
SERVER-42307 $lookup overwrites the entire object and erases fields (other than what "as" holds) when used inside an array of nested objects
-
- Closed
-
- related to
-
SERVER-28717 $lookup does not expand 'localField' as expected when it is a dotted path representing fields within an array
-
- Closed
-