[SERVER-74531] Exclude projection messed up the object fields order Created: 02/Mar/23  Updated: 29/Oct/23  Resolved: 25/Apr/23

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 7.1.0-rc0, 7.0.0-rc1

Type: Bug Priority: Major - P3
Reporter: Zixuan Zhuang Assignee: Drew Paroski
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Backports
Depends
is depended on by SERVER-76510 Make makeBsonObj() preserve field order Closed
Problem/Incident
Backwards Compatibility: Fully Compatible
Operating System: ALL
Backport Requested:
v7.0
Sprint: QE 2023-03-06, QE 2023-03-20, QE 2023-04-03, QE 2023-04-17, QE 2023-05-01
Participants:
Linked BF Score: 35

 Description   

SBE re-orders the fields in bson with the project stage {$project: {"obj.obj.obj.obj.array": 0}}.

In SBE's implementation, the object {obj: xx, any:xx } is first copied without specific field excluded from projections (obj in this case), then append the field back if only part of the object is excluded (only obj.array is excluded in this case). With this algorithm, the fields order is changed after projection stage.

When there is a $lookup stage with self-lookup after the project stage, the re-ordered object can't be matched to the original object, and output incorrect result.



 Comments   
Comment by Githook User [ 10/May/23 ]

Author:

{'name': 'Drew Paroski', 'email': 'drew.paroski@mongodb.com', 'username': 'paroski'}

Message: SERVER-74531 Make MakeObjStage respect original field order

(cherry picked from commit e4af7edec98c1b05b2b16fd4e664777f6a5cb398)
Branch: v7.0
https://github.com/mongodb/mongo/commit/d2d601b85b38b06e28bdb4fd5c70c4a4973e84f9

Comment by Zixuan Zhuang [ 19/Apr/23 ]

kelsey.schubert@mongodb.com 6.3 and 7.0 are affected. Prior to 6.3, SBE is not enabled by default so it depends on if the query with $lookup and $project uses SBE.

Comment by Githook User [ 19/Apr/23 ]

Author:

{'name': 'Drew Paroski', 'email': 'drew.paroski@mongodb.com', 'username': 'paroski'}

Message: SERVER-74531 Make MakeObjStage respect original field order
Branch: master
https://github.com/mongodb/mongo/commit/e4af7edec98c1b05b2b16fd4e664777f6a5cb398

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