[SERVER-66584] sh.updateZoneKeyRange() does not support $minKey or $maxKey Created: 19/May/22  Updated: 27/Oct/23  Resolved: 19/May/22

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

Type: Task Priority: Major - P3
Reporter: Frederic Vitzikam Assignee: Max Hirschhorn
Resolution: Works as Designed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
is related to SERVER-32862 sh.addShardToZone() allows unusual (i... Closed
is related to SERVER-34644 Disable `DollarPrefixedFieldName` che... Closed
Sprint: Sharding NYC 2022-05-30
Participants:

 Description   

The following commands do not seem to work on a sharded cluster, I ran them by hand through the shell:

sh.updateZoneKeyRange("foo.bar", { "key": { "$minKey": 1 } }, { "key": { "$maxKey": 1 } }, "zone")
sh.updateZoneKeyRange("foo.bar", { "key": { "$minKey": 1 } }, { "key": 50 }, "zone")
sh.updateZoneKeyRange("foo.bar", { "key": 50 }, { "key": { "$maxKey": 1 } }, "zone") 

as it complains about

"errmsg" : "min: { key: { $minKey: 1.0 } } should be less than max: { key: { $maxKey: 1.0 } }",

I found https://jira.mongodb.org/browse/SERVER-32862, where there is a comment "Another interesting aspect is the following" about a similar bug (different from the main bug of that issue that was fixed).

 

Using MinKey/MaxKey like in https://www.mongodb.com/docs/manual/reference/method/sh.updateZoneKeyRange/ does work.



 Comments   
Comment by Max Hirschhorn [ 19/May/22 ]

So it is not supposed to work ?

The server erroring here is correct. The string "$minKey" is truly greater than the string "$maxKey". { "$minKey": 1 } and MinKey are not the same thing. It is only the mongo shell which confusingly displays them that way.

> bsonWoCompare(MinKey, { "$minKey": 1 })
-21
> bsonWoCompare(MaxKey, { "$maxKey": 1 })
107

> MinKey
{ "$minKey" : 1 }
> MaxKey
{ "$maxKey" : 1 }

Comment by Frederic Vitzikam [ 19/May/22 ]

So it is not supposed to work ?

Comment by Max Hirschhorn [ 19/May/22 ]

Hi frederic.vitzikam@mongodb.com, it looks like there may be some confusion due to how the mongo shell displays the MinKey and MaxKey values.

{ "$minKey": 1 } a BSON Object (type 0x03). MinKey is the literal MinKey value (type 0xFF).

https://bsonspec.org/spec.html

The literal object { "$minKey": 1 } compares greater than the literal object { "$maxKey": 1 } because 'i' comes after 'a'.

> bsonWoCompare({ "$minKey": 1 }, { "$maxKey": 1 })
1
> bsonWoCompare(MinKey, MaxKey)
-128

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