Join Optimimization: "Location4822820: duplicate field" error when projecting the same field twice

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Fixed
    • Priority: Major - P3
    • 8.3.0-rc0
    • Affects Version/s: None
    • Component/s: None
    • None
    • Query Execution
    • Fully Compatible
    • ALL
    • QE 2026-01-19, QE 2026-01-05, QE 2025-12-22
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      This:

      db.adminCommand({setParameter: 1, internalEnableJoinOptimization: true});
      db.foo.drop();
      db.bar.drop();
      
      db.foo.insert({f: 1, g: 1});
      db.bar.insert({a: 1});
      
      db.foo.aggregate([
       		{
       			"$project" : {
       				"f" : "$g",
       				"g" : 1,
       			}
       		},
       		{
       			"$lookup" : {
       				"from" : "bar",
       				"localField" : "_id",
       				"foreignField" : "_id",
       				"as" : "y"
       			}
       		},
       		{
       			"$unwind" : "$y"
       		},
       	]);
      

      results in this:

      MongoServerError[Location4822820]: duplicate field: 4
      

      Not reproducible with internalEnableJoinOptimization set to false.
      Not reproducible with featureFlagSbeFull alone. internalEnableJoinOptimization is required.

            Assignee:
            Alberto Massari
            Reporter:
            Philip Stoev
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: