[SERVER-30695] Ignore field order when using JSON Schema to compare object literals Created: 16/Aug/17 Updated: 30/Oct/23 Resolved: 20/Sep/17 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Querying |
| Affects Version/s: | None |
| Fix Version/s: | 3.6.0-rc0 |
| Type: | Task | Priority: | Major - P3 |
| Reporter: | Kyle Suarez | Assignee: | Kyle Suarez |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||
| Backwards Compatibility: | Fully Compatible | ||||||||
| Sprint: | Query 2017-10-02 | ||||||||
| Participants: | |||||||||
| Description |
|
Though an uncommon case, it's possible for a user to compare object literals directly using JSON Schema's enum keyword:
This will currently use MongoDB's object comparison semantics, which takes field order into account. However, RFC 7159 ยง1 states that:
This implies that $jsonSchema object-to-object comparisons should be done without regard to field order, as JSON Schema adheres to the JSON spec. |
| Comments |
| Comment by Githook User [ 20/Sep/17 ] | |
|
Author: {'email': 'kyle.suarez@mongodb.com', 'name': 'Kyle Suarez', 'username': 'ksuarz'}Message: | |
| Comment by Kyle Suarez [ 18/Sep/17 ] | |
|
david.storch, I forgot to sent the sprint field when we last moved this from Nick to myself. I'm pulling it into the sprint, since I can fix "uniqueItems" after "enum" and the comparators go in. | |
| Comment by Kyle Suarez [ 15/Sep/17 ] | |
|
Assigning to me since Nick will have done this already for enum, but I still have to update uniqueItems. | |
| Comment by David Storch [ 17/Aug/17 ] | |
|
I believe the problem described here applies to comparisons made for the uniqueItems keyword, in addition to enum. | |
| Comment by Kyle Suarez [ 16/Aug/17 ] | |
|
You can work around this by writing your schema in a way that does not use object-object comparisons. For example, the schema in the description could be rewritten as
|