$lookup against a view with a desugaring stage returns incorrect results

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Fixed
    • Priority: Major - P3
    • 9.1.0-rc0, 9.0.0-rc4
    • Affects Version/s: None
    • Component/s: None
    • None
    • Query Integration
    • Fully Compatible
    • ALL
    • v9.0
    • Hide
      import {ShardingTest} from "jstests/libs/shardingtest.js";
      
      const st = new ShardingTest({shards: 1});
      const testDB = st.s.getDB(jsTestName());
      assert.commandWorked(st.s.adminCommand({enableSharding: testDB.getName()}));
      
      assert.commandWorked(
          testDB.sales.insertMany([{product: "widget"}, {product: "widget"}, {product: "gizmo"}]));
      assert.commandWorked(
          testDB.createView("topSeller", "sales", [{$sortByCount: "$product"}, {$limit: 1}]));
      assert.commandWorked(testDB.reports.insert({product: "gizmo"}));
      
      const res =
          testDB.reports
              .aggregate(
                  [{$lookup: {from: "topSeller", localField: "product", foreignField: "_id", as: "t"}}])
              .toArray();
      
      // "gizmo" should not match, since "widget" is the top seller. "t" should be empty
      assert.eq(0, res[0].t.length);
      
      st.stop();
      
      Show
      import {ShardingTest} from "jstests/libs/shardingtest.js" ; const st = new ShardingTest({shards: 1}); const testDB = st.s.getDB(jsTestName()); assert .commandWorked(st.s.adminCommand({enableSharding: testDB.getName()})); assert .commandWorked( testDB.sales.insertMany([{product: "widget" }, {product: "widget" }, {product: "gizmo" }])); assert .commandWorked( testDB.createView( "topSeller" , "sales" , [{$sortByCount: "$product" }, {$limit: 1}])); assert .commandWorked(testDB.reports.insert({product: "gizmo" })); const res = testDB.reports .aggregate( [{$lookup: {from: "topSeller" , localField: "product" , foreignField: "_id" , as: "t" }}]) .toArray(); // "gizmo" should not match, since "widget" is the top seller. "t" should be empty assert .eq(0, res[0].t.length); st.stop();
    • None
    • None
    • None
    • None
    • None
    • None
    • None

          Assignee:
          Finley Lau
          Reporter:
          Matt Boros
          Votes:
          0 Vote for this issue
          Watchers:
          6 Start watching this issue

            Created:
            Updated:
            Resolved: