[SERVER-63656] $match + $expr in nested pipeline fails to resolve variable definition on on mongos Created: 15/Feb/22  Updated: 15/Dec/22  Resolved: 15/Apr/22

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

Type: Bug Priority: Major - P3
Reporter: Alya Berciu Assignee: Steve Tarzia
Resolution: Won't Fix Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
Operating System: ALL
Steps To Reproduce:

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 } ] }

Participants:

 Description   

See the steps to reproduce.


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