-
Type: Task
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: None
-
Labels:
Description:
This change added in a mongo shell function "convertShardKeyToHashed". This function converts a bson key value pair into the hashed value that would be used for indexing/sharding.
Example usage from the source:
/** * This function computes a hash value for a document. * Specifically, this is the same hash function that is used to form a hashed index, * and thus used to generate shard keys for a collection. * * e.g. * > // For a given collection prepared like so: * > use mydb * > db.mycollection.createIndex({ x: "hashed" }) * > sh.shardCollection("mydb.mycollection", { x: "hashed" }) * > // And a sample object like so: * > var obj = { x: "Whatever key", y: 2, z: 10.0 } * > // The hashed value of the shard key can be acquired from the shard key-value pair like so: * > convertShardKeyToHashed({x: "Whatever key"}) */
Scope of changes:
- 4.0
- new ref page and toc pages
- add link to new page from hash index page
- add link to new page from /core/hashed-sharding.txt
Not adding to general mentions about hashed sharding/hashed indexes; e.g.:
- indexes
- sharding
- move chunk – since you would sh.status to get the bounds of the chunk to move
- etc.
Impact to other docs outside of this product:
none
MVP:
Resources:
Engineering Ticket Description:
Users may sometimes want to figure out the hashed value for a certain document's shard key field. For instance the reason for doing that might be to identify the shard key range / chunk the document belongs to (when a hashed shard key is used). There a ways to do that, namely:
- Run a query on the shard key and inspect the index key (the `$returnKey` query option)
- Run a query on the shard key and inspect the index scan bounds in the $explain output
- Re-start the server in test mode and use the _hashBSONElement command
- Port BSONElementHasher into a custom application
All of these methods are pretty clumsy and inefficient when all you need is to get a hashed value for an arbitrary field. It would be much user-friendly if BSONElementHasher could be run on the client side (i.e. in the mongo shell) via a helper function.
- documents
-
SERVER-32889 Mongo shell injection function for hashing shard key
- Closed