[SERVER-74725] Query SortPattern does not check for duplicate fields Created: 09/Mar/23 Updated: 29/Oct/23 Resolved: 28/Apr/23 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | 7.1.0-rc0 |
| Type: | Task | Priority: | Major - P3 |
| Reporter: | Ian Boros | Assignee: | Peter Volk |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | neweng | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||||||||||||||
| Assigned Teams: |
Query Optimization
|
||||||||||||||||||||
| Backwards Compatibility: | Minor Change | ||||||||||||||||||||
| Sprint: | QO 2023-04-17, QO 2023-05-01 | ||||||||||||||||||||
| Participants: | |||||||||||||||||||||
| Description |
|
The SortPattern constructors do not check for duplicate paths being in the sort pattern, e.g. {a:1, b:1, a:1}. This is something we should check for and disallow. There may be existing places in our codebase where a sort pattern with duplicate field names are created by accident. |
| Comments |
| Comment by Githook User [ 28/Apr/23 ] |
|
Author: {'name': 'Peter Volk', 'email': 'peter.volk@mongodb.com', 'username': 'HCSPete'}Message: |
| Comment by Ian Boros [ 06/Apr/23 ] |
|
Hi, What you're probably seeing there is the javascript behavior for when an object is created with duplicate keys. It is possible for a user to send us a sort spec BSON with duplicate keys, it's just not possible (or, not easy) to do this in the mongo shell. So to answer your question, it does change user facing behavior, but only in the case where the user was sending us BSON with duplicate fields. Generally the server is "unfriendly" to BSON with duplicate keys anyway. |
| Comment by Peter Volk [ 06/Apr/23 ] |
|
ian.boros@mongodb.com Should this also change the user facing behavior for anything in $sort or only the behavior of the internally used class? In the current version the last sort of the field overwrites all previously defined sorting order and only the last wins. |
| Comment by Ian Boros [ 04/Apr/23 ] |
|
That's a duplicate. |
| Comment by Peter Volk [ 04/Apr/23 ] |
|
ian.boros@mongodb.com Should the sort pattern such as {a:1, a:1, b:1} still be allowed or should this also be considered a duplicate? |