[SERVER-32889] Mongo shell injection function for hashing shard key Created: 25/Jan/18 Updated: 30/Oct/23 Resolved: 23/Apr/18 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Shell |
| Affects Version/s: | None |
| Fix Version/s: | 3.7.6 |
| Type: | Improvement | Priority: | Minor - P4 |
| Reporter: | Dmitry Ryabtsev | Assignee: | Benjamin Caimano (Inactive) |
| Resolution: | Fixed | Votes: | 1 |
| Labels: | neweng | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||||||||||
| Backwards Compatibility: | Fully Compatible | ||||||||||||||||
| Sprint: | Platforms 2018-04-09, Platforms 2018-04-23, Platforms 2018-05-07 | ||||||||||||||||
| Participants: | |||||||||||||||||
| 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:
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. |
| Comments |
| Comment by Dmitry Ryabtsev [ 16/Aug/18 ] | |||||||||||||||||||||||||||||||
|
Hi ben.caimano, apologies for the late reply. I'm pretty happy with this implementation, granted that the point raised by Kev gets addressed ( Thank you! | |||||||||||||||||||||||||||||||
| Comment by Kevin Pulo [ 16/Aug/18 ] | |||||||||||||||||||||||||||||||
|
Thanks ben.caimano, I just used this for the first time and it's very useful! One thing I noticed, though, is that convertShardKeyToHashed() takes just the value to be hashed. So in the typical usage of a hashed shard key, you just want to do convertShardKeyToHashed(Value), ie. without the ShardKey field prefix.
| |||||||||||||||||||||||||||||||
| Comment by Benjamin Caimano (Inactive) [ 23/Apr/18 ] | |||||||||||||||||||||||||||||||
|
I've added the following function as a shell injection:
dmitry.ryabtsev, does this cover your bases? | |||||||||||||||||||||||||||||||
| Comment by Githook User [ 23/Apr/18 ] | |||||||||||||||||||||||||||||||
|
Author: {'email': 'ben.caimano@10gen.com', 'name': 'Ben Caimano'}Message: |