[SERVER-43669] $meta:"sortKey" expressions can generate BSON with duplicate field names which are not correctly handled by Document/Value class Created: 26/Sep/19  Updated: 29/Oct/23  Resolved: 13/Dec/19

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

Type: Bug Priority: Major - P3
Reporter: Justin Seyster Assignee: Justin Seyster
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
is depended on by DRIVERS-806 $meta:"sortKey" expressions can gener... Closed
Documented
is documented by DOCS-13301 Investigate changes in SERVER-43669: ... Closed
Related
is related to SERVER-43361 Remove compatibility for 4.2 $sortKey... Closed
Backwards Compatibility: Minor Change
Operating System: ALL
Sprint: Query 2019-11-04, Query 2019-11-18, Query 2019-12-02, Query 2019-12-16, Query 2019-12-30
Participants:

 Description   

If a document has a compound sort key (e.g.:

{"": 1, "": 2}

) and an expression tries to manipulate it, the result may only take one of the fields into account. For example, if the user tries to use {$objectToArray: {$meta: "sortKey"}}, the resulting array only has the first element (

{k: "", v: 1}

).

I haven't encountered any cases yet, but it's possible that as we use Document/Value more we'll run into internal cases where we are manipulating Documents with duplicate fields.

In general, there is no invariant that all field names in a BSONObj are unique, but the only safe way to have a Document with duplicate field names is when you create it from a BSONObj and convert back to a BSONObj with no transformations (so that the lazy conversion behavior just returns the original BSONObj).



 Comments   
Comment by Githook User [ 13/Dec/19 ]

Author:

{'name': 'Justin Seyster', 'email': 'justin.seyster@mongodb.com', 'username': 'jseyster'}

Message: SERVER-43669 Serialize "sortKey" as BSONArray
Branch: master
https://github.com/mongodb/mongo/commit/3a62fec23a50653994e01d1b1725d80a10fc208d

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