$lookup localField/foreignField numeric path traversal differs from let syntax

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Cannot Reproduce
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • Query Optimization
    • ALL
    • Hide

       

      const collNumeric = db.collNumeric;
      collNumeric.drop();
      assert.commandWorked(collNumeric.insertOne({a: [1, 2], b: 1}));
      assert.commandWorked(collNumeric.createIndex({"a.0": 1}));
      
      const coll1 = db.coll1;
      coll1.drop();
      assert.commandWorked(coll1.insertOne({a: 1, b: 1, x: {c: 1}}));
      
      // This $lookup query joins with one doc:
      collNumeric.aggregate({$lookup: {from: coll1.getName(), localField: "a.0", foreignField: "a", as: "joined"}});
      
      // But this one joins with 0 docs
      collNumeric.aggregate({
                      $lookup: {
                          from: coll1.getName(),
                          let: {aa: "$a.0"},
                          pipeline: [{$match: {$expr: {$eq: ["$$aa", "$a"]}}}],
                          as: "joined",
                      },
      })
      Show
        const collNumeric = db.collNumeric; collNumeric.drop(); assert.commandWorked(collNumeric.insertOne({a: [1, 2], b: 1})); assert.commandWorked(collNumeric.createIndex({"a.0": 1})); const coll1 = db.coll1; coll1.drop(); assert.commandWorked(coll1.insertOne({a: 1, b: 1, x: {c: 1}})); // This $lookup query joins with one doc: collNumeric.aggregate({$lookup: {from: coll1.getName(), localField: "a.0", foreignField: "a", as: "joined"}}); // But this one joins with 0 docs collNumeric.aggregate({                 $lookup: {                     from: coll1.getName(),                     let: {aa: "$a.0"},                     pipeline: [{$match: {$expr: {$eq: ["$$aa", "$a"]}}}],                     as: "joined",                 }, })
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      Assigning a let variable in a $lookup to a numeric field path appears to set this variable to an incorrect value (see repro steps below).

            Assignee:
            Unassigned
            Reporter:
            Alya Berciu
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: