Question about relate fields of compose hash shard key

Since 4.4 mongodb support compose hashed shard key, but I can not find any document that talk about role of additional fields of the shardkey, for example my shardkey is:

{oemNumber: “hashed”, zipCode: 1, supplierId: 1}

what zipCode and SupplierId fields will do and what do they help for sharding, thanks ! :blush:

Hi @_Jin and welcome to the community.

The following document on Compound Sharded key is useful for understanding the ideas of Sharding on Compound Indexes.

Having multiple fields as part of the compound shard key would be good for a monotonically increasing value where a monotonically increasing shard key could be an issue, since it could mean that your inserts would be directed toward a “hot shard” where one shard is doing all the insertion works and all the other shards not participating in the workload, thus reducing the benefits of using a sharded cluster in the first place

Thus to answer your question, combining a hashed shard key with other keys in a compound shard key would help with the shard key’s cardinality and also could potentially be used to help with range & sorting queries

Please let us know if you have any other questions.