$addFields recreates an array element deleted by projection

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Duplicate
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • Query Execution
    • ALL
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      Example:

      db.agg_test.insertOne({"a": [31415, 9265]});
      db.agg_test.aggregate([{$project: {"a.b": 1, "c": {$const: "test"}}}, {$addFields: {"a.d": "zzz"}}]); 

      Result would be:

       "a" : [ { "d" : "zzz" }, { "d" : "zzz" } ], "c" : "test" }

      Projection {"a.b": 1} will remove all scalar elements from the array "a" as per projection definition.

      Additional $const expression is needed to use default projection implementation instead of a simplified one.

      When projection iterates through array, it replaces deleted scalar values with "missing " values and then $addFields stage replaces "missing" values with objects.

       

       

            Assignee:
            [DO NOT USE] Backlog - Query Execution
            Reporter:
            Ivan Fefer
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: