[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:
Depends
depends on SERVER-30176 Extend the JSON Schema parser to hand... Closed
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:

{enum: [{a: 1, b: 1}]}

This will currently use MongoDB's object comparison semantics, which takes field order into account. However, RFC 7159 ยง1 states that:

An object is an unordered collection of zero or more name/value pairs, where a name is a string and a value is a string, number, boolean, null, object, or array.

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: SERVER-30695 uniqueItems must ignore field order when comparing documents
Branch: master
https://github.com/mongodb/mongo/commit/7a15db88968b9f6dd4418f4a89a2826c82b2ecac

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

{properties: {a: {enum: [1]}, b: {enum: [2]}}}

Generated at Thu Feb 08 04:24:42 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.