-
Type:
Bug
-
Resolution: Done
-
Priority:
Critical - P2
-
None
-
Affects Version/s: 3.4.9, 3.6.0-rc0, 6.3.2, 6.0.10, 5.0.21
-
Component/s: Aggregation Framework
-
Query Optimization
-
Fully Compatible
-
ALL
-
-
QO 2023-08-21, QO 2023-09-04, QO 2023-09-18
-
None
-
None
-
None
-
None
-
None
-
None
-
None
If an array element is used as the localField for the $lookup aggregation pipe, a $project anywhere else in the pipeline will fail to return results and also take a while to run. There is a workaround by adding a field containing the local element and using that field as the localField:
db.venues.aggregate(
// Pipeline
[
// Stage 1
{
$addFields: {
"firstChainId": {
"$arrayElemAt": [ "$chainIds", 0 ]
}
}
},
// Stage 2
{
$lookup: {
"from" : "chains",
"localField" : "firstChainId",
"foreignField" : "_id",
"as" : "venueChain"
}
},
// Stage 3
{
$addFields: {
"chainName": "$venueChain.name"
}
},
// Stage 4
{
$project: {
n: 1,
chainName: 1
}
},
],
// Options
{
cursor: {
batchSize: 50
}
}
);
- is related to
-
SERVER-25200 $project computed fields on arrays sets every element of the array -- inconsistent with $set
-
- Closed
-
- related to
-
SERVER-26066 $project should add top-level field to dependencies for nested computed fields
-
- Closed
-