[SERVER-51383] bsonWoCompare on embedded documents/objects does not match ordering described in documentation Created: 05/Oct/20  Updated: 06/Oct/20  Resolved: 06/Oct/20

Status: Closed
Project: Core Server
Component/s: Index Maintenance, Querying
Affects Version/s: 4.2.9
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Scott Crunkleton Assignee: Eric Sedor
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-51258 Unexpected behavior in range query on... Closed
Operating System: ALL
Participants:

 Description   

According to https://docs.mongodb.com/manual/reference/bson-type-comparison-order/#objects objects are compared field-by-field (in order that they're stored):
1. by field key name
2. by field value

I ran into some issues with some queries and after some research, I have some interesting results from bsonWoCompare:

> bsonWoCompare({foo: 0}, {bar: 1})
1
> bsonWoCompare({foo: 0}, {bar: "BAR"})
-5
> bsonWoCompare({foo: true}, {bar: "BAR"})
25
> bsonWoCompare({foo: ""}, {bar: "BAR"})
1
> bsonWoCompare({foo: MinKey()}, {bar: "BAR"})
-16
> bsonWoCompare({foo: MaxKey()}, {bar: "BAR"})
112

Since "foo" > "bar", shouldn't bsonWoCompare always return a positive result, regardless of field values?

 



 Comments   
Comment by Eric Sedor [ 06/Oct/20 ]

Transferring some content to SERVER-51258 and continuing there.

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