Details
Description
The following command should work, but doesn't on a mongos:
{
|
aggregate: 'coll0', |
pipeline: [
|
{
|
'$match': { '$expr': { '$eq': [ '$_id', 2] } } |
},
|
{ '$project': { _id: 0, y: '$$y'} } |
],
|
let: { y: { '$literal': '$bar' } }, |
cursor: {}
|
}
|
If you look at the profiler in the shards, it looks like we just need to preserve a $const or $literal in the serialization. That is dropped and we just end up with y: "$bar":
{
|
"op" : "command", |
"ns" : "test.coll0", |
"command" : { |
"aggregate" : "coll0", |
"pipeline" : [ |
{
|
"$match" : { |
"$expr" : { |
"$eq" : [ |
"$_id", |
2
|
]
|
}
|
}
|
},
|
{
|
"$project" : { |
"_id" : 0, |
"y" : "$$y" |
}
|
}
|
],
|
"cursor" : { |
"batchSize" : NumberLong(101) |
},
|
"let" : { |
"y" : "$bar" |
},
|
"fromMongos" : false, |
"readConcern" : { |
"level" : "local", |
"provenance" : "implicitDefault" |
},
|
"writeConcern" : { |
"w" : "majority", |
"wtimeout" : 0, |
"provenance" : "customDefault" |
},
|
"shardVersion" : [ |
Timestamp(0, 0),
|
ObjectId("000000000000000000000000") |
],
|
"databaseVersion" : { |
"uuid" : UUID("d40d3f32-02c0-42aa-939d-2d5f640d43b6"), |
"timestamp" : Timestamp(1622740896, 32), |
"lastMod" : 1 |
},
|
"lsid" : { |
"id" : UUID("bd190341-9e6d-4458-b8df-35a7dd5a5072"), |
"uid" : BinData(0,"47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=") |
},
|
"$clusterTime" : { |
"clusterTime" : Timestamp(1622741302, 25), |
"signature" : { |
"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="), |
"keyId" : NumberLong(0) |
}
|
},
|
"$configTime" : Timestamp(1622741302, 25), |
"$topologyTime" : Timestamp(1622740776, 3), |
"$client" : { |
"application" : { |
"name" : "MongoDB Shell" |
},
|
"driver" : { |
"name" : "MongoDB Internal Client", |
"version" : "5.0.0-rc0" |
},
|
"os" : { |
"type" : "Darwin", |
"name" : "Mac OS X", |
"architecture" : "x86_64", |
"version" : "19.4.0" |
},
|
"mongos" : { |
"host" : "charlie-macbook-pro:20003", |
"client" : "127.0.0.1:54610", |
"version" : "5.0.0-rc0" |
}
|
},
|
"$configServerState" : { |
"opTime" : { |
"ts" : Timestamp(1622741302, 25), |
"t" : NumberLong(-1) |
}
|
},
|
"$db" : "test" |
},
|
"numYield" : 0, |
"locks" : { |
"Global" : { |
"acquireCount" : { |
"r" : NumberLong(1) |
}
|
},
|
"Mutex" : { |
"acquireCount" : { |
"r" : NumberLong(2) |
}
|
}
|
},
|
"flowControl" : { |
|
},
|
"readConcern" : { |
"level" : "local", |
"provenance" : "implicitDefault" |
},
|
"writeConcern" : { |
"w" : "majority", |
"wtimeout" : 0, |
"provenance" : "customDefault" |
},
|
"ok" : 0, |
"errMsg" : "Command let Expression tried to access a field, but this is not allowed because Command let Expressions run before the query examines any documents.", |
"errName" : "Location4890500", |
"errCode" : 4890500, |
"responseLength" : 578, |
"protocol" : "op_msg", |
"millis" : 0, |
"ts" : ISODate("2021-06-03T17:28:30.794Z"), |
"client" : "127.0.0.1", |
"appName" : "MongoDB Shell", |
"allUsers" : [ ], |
"user" : "" |
}
|
Attachments
Issue Links
- is depended on by
-
DRIVERS-776 Support 'let' option for aggregate command
-
- Closed
-
- is related to
-
SERVER-46707 Support 'let' variables in aggregate command in sharded deployments
-
- Closed
-
- related to
-
SERVER-69504 Leave index build phase intact upon exception during collection scan
-
- Closed
-