• Type: Bug
    • Resolution: Unresolved
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • ALL
    • Hide

      Affects versions: 9.0.8 and master (2f8d82a7, 2026-11-18). Default server parameters. Standalone mongod; Ubuntu 24.04 x86_64 and macOS arm64 give the same output.

      Repro

      db = db.getSiblingDB("test");
      db.c.drop();
      db.c.insertOne({_id: 1, b: [1]});
      const project = {$project: {"b.x": {$literal: 1}, "b.y": 1}};
      const match = {$match: {"b.y": null}};
      print("[$project]:                        " + EJSON.stringify(db.c.aggregate([project]).toArray()));
      print("[$project, $match {'b.y': null}]:  " + EJSON.stringify(db.c.aggregate([project, match]).toArray()));
      print("same, $match behind a $facet:      " + EJSON.stringify(db.c.aggregate([{$facet: {r: [project]}}, {$unwind: "$r"}, {$replaceRoot: {newRoot: "$r"}}, match]).toArray()));
      

      Output (9.0.8)

      [$project]:                        [{"_id":1,"b":[{"x":1}]}]
      [$project, $match {'b.y': null}]:  []
      same, $match behind a $facet:      [{"_id":1,"b":[{"x":1}]}]
      

      Master 2f8d82a7 prints the same lines.

      Show
      Affects versions: 9.0.8 and master (2f8d82a7, 2026-11-18). Default server parameters. Standalone mongod; Ubuntu 24.04 x86_64 and macOS arm64 give the same output. Repro db = db.getSiblingDB( "test" ); db.c.drop(); db.c.insertOne({_id: 1, b: [1]}); const project = {$project: { "b.x" : {$literal: 1}, "b.y" : 1}}; const match = {$match: { "b.y" : null }}; print( "[$project]: " + EJSON.stringify(db.c.aggregate([project]).toArray())); print( "[$project, $match { 'b.y' : null }]: " + EJSON.stringify(db.c.aggregate([project, match]).toArray())); print( "same, $match behind a $facet: " + EJSON.stringify(db.c.aggregate([{$facet: {r: [project]}}, {$unwind: "$r" }, {$replaceRoot: {newRoot: "$r" }}, match]).toArray())); Output (9.0.8) [$project]: [{"_id":1,"b":[{"x":1}]}] [$project, $match {'b.y': null}]: [] same, $match behind a $facet: [{"_id":1,"b":[{"x":1}]}] Master 2f8d82a7 prints the same lines.
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      An inclusion $project that computes b.x and includes b.y turns {b: [1]} into {b: [{x: 1}]}, which matches {"b.y": null}. But [$project, $match {"b.y": null}] returns no documents: the $match is moved ahead of the $project, where b is still [1] and does not match. Putting the $match behind a $facet returns the document.

      Related

      • SERVER-139258 (Needs Scheduling): names the same semantic gap; no wrong result reported.
      • SERVER-134187 (In Code Review): arrayness of a dotted path after an inclusion projection with a computed field is reported wrong; its fix may cover this.

      Found with Ephyra, a property-based testing tool I'm developing; this report was drafted with an LLM from the test output, and I reviewed it and reran the repro on 9.0.8 and master.

            Assignee:
            Benjamin Ulmer
            Reporter:
            Alperen Keleş (EXT)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: