Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-70860

$addFields recreates an array element deleted by projection

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: Major - P3 Major - P3
    • None
    • None
    • None
    • None
    • Query Execution
    • ALL

    Description

      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.

       

       

      Attachments

        Activity

          People

            backlog-query-execution Backlog - Query Execution
            ivan.fefer@mongodb.com Ivan Fefer
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: