[SERVER-70860] $addFields recreates an array element deleted by projection Created: 26/Oct/22  Updated: 05/Dec/22  Resolved: 04/Nov/22

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Ivan Fefer Assignee: Backlog - Query Execution
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-50779 ProjectionExecutor incorrectly leaves... Backlog
Assigned Teams:
Query Execution
Operating System: ALL
Participants:

 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.

 

 



 Comments   
Comment by Ivan Fefer [ 04/Nov/22 ]

Closing this in favor of more general ticket SERVER-50779

Generated at Thu Feb 08 06:17:20 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.