[SERVER-48403] $addFields may add new fields in a different order in certain cases Created: 26/May/20  Updated: 21/Jul/20  Resolved: 17/Jul/20

Status: Closed
Project: Core Server
Component/s: Aggregation Framework
Affects Version/s: 4.2 Required
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Anton Korshunov Assignee: Anton Korshunov
Resolution: Duplicate Votes: 0
Labels: qexec-team
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
Related
Operating System: ALL
Steps To Reproduce:

 

db.coll.drop()
db.coll.insert({_id:1, obj: {obj: {}}})
db.coll.aggregate([{$project: {“obj.obj.obj.str”: 1}},  {$addFields: {“obj.obj.array”:  ‘abc’, “obj.obj.obj.num”: ‘xyz’}}])  
 
{ “_id” : 1, “obj” : { “obj” : { “obj” : { “num” : “xyz” }, “array” : “abc” } } }
  
// Now we just add a $match stage, and the order of new fields changes.
db.coll.aggregate([{$match: {_id: 1}}, {$project: {“obj.obj.obj.str”: 1}},  {$addFields: {“obj.obj.array”:  ‘abc’, “obj.obj.obj.num”: ‘xyz’}}])  
 
{ “_id” : 1, “obj” : { “obj” : { “array” : “abc”, “obj” : { “num” : “xyz” } } }

 

 

Sprint: Query 2020-06-29, Query 2020-07-13, Query 2020-07-27
Participants:
Linked BF Score: 11

 Description   

Under certain conditions $addFields may add new fields to the output document in a different order, even when applied to the same input document.

 

Note that this behaviour was changed in 4.4 when find and aggregate projections were unified, and the order of new fields is always the same as in $addFields specification.


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