MongoDB Using String-Type Shard Key for Zone Ranges
2
votes
1
answer
1702
views
Mongo lets any field type be used to set ranges for Shard Zones, but doesn't specify how analyses are conducted.
My goal is to point queries and writes at the exact right server, WITHOUT using a compound shard key (for various execution complexities).
I want to embed a unique user alpha-numeric ID, plus a latitude and longitude value into a single string, and use this as my shard key.
Ex: (ID.lat.lon) "4kjaj29.48.-89"
Would fall within the range:
"0000000.45.-100" to "zzzzzzz.50.-80"
Mongo uses utf8 strings, https://www.utf8-chartable.de/unicode-utf8-table.pl , in which for alpha-numeric characters 0 is the "least" and z is the "greatest".
So I have to imagine this is how range inclusion is computed? Does anyone know off-hand if this approach is correct? And if not, can you point me in the right direction to accomplish this?
There is definitely a way to accomplish this, since some kind of range inclusions calculation is occurring with string types, but just requires knowing the analysis strategy.
Asked by Gukki5
(121 rep)
Jul 17, 2018, 03:41 AM
Last activity: May 8, 2025, 02:09 AM
Last activity: May 8, 2025, 02:09 AM