On a sharded cluster (with the coll collection unsharded), the following command fails with the messageĀ "Use of undefined variable: var":
db.coll.insert({a: 1})
db.coll.aggregate({$lookup: {from: "coll", as: "coll", let: {var: "$a"}, pipeline: [
{$unionWith: {coll: "coll", pipeline: [
{$match: {$expr: {$eq: ["$a", "$$var"]}}}]}}]}})
However, running this against a mongod returns:
{ "_id" : ObjectId("620bc09e443b85085d27efd5"), "a" : 1, "coll" : [ { "_id" : ObjectId("620bc09e443b85085d27efd5"), "a" : 1 }, { "_id" : ObjectId("620bc09e443b85085d27efd5"), "a" : 1 } ] }
See the steps to reproduce.