Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-77991

$$USER_ROLES not available within aggregation sub-pipeline

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 7.2.0-rc0, 7.0.2, 7.1.0-rc3
    • Affects Version/s: None
    • Component/s: None
    • None
    • Query Optimization
    • Fully Compatible
    • ALL
    • v7.1, v7.0
    • QO 2023-09-04, QO 2023-09-18

      The query 

      db.coll.aggregate([{$lookup: {from: "other", let: {role: "$role"}, pipeline:[{$match:{$expr: {$eq:["$role", "$$USER_ROLES.role"]}}}], as: "out"}}])
      

      fails with the error "PlanExecutor error during aggregation :: caused by :: error while multiplanner was selecting best plan :: caused by :: Builtin variable '$$USER_ROLES' is not available" (code 51144).

       

      Given that the query 

      db.other.aggregate([{$match: {$expr: {$eq: ["$role", "$$USER_ROLES.role"]}}}])
      

      succeeds and behaves as anticipated, I suspect this is due to $$USER_ROLES not being set properly for a sub-pipeline.

            Assignee:
            militsa.sotirova@mongodb.com Militsa Sotirova
            Reporter:
            will.buerger@mongodb.com Will Buerger
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: