What are the requirements for using compound index as a shard key in Mongo?

1.2k Views Asked by At

What are the requirements for using compound index as a shard key in MongoDB(2.0.4 specifically). I read somewhere that key components must be unique, is that so? What are other thing that one should consider while designing compound shard key? Does the order of key components matter?

1

There are 1 best solutions below

0
On BEST ANSWER

This topic is covered in many places in general:

As to your specific questions, the shard key does not have to be unique, though often people do configure it that way. You are probably referring to the fact that the shard key is immutable (also discussed above).

You should also consider that all (non-multi)updates, upserts, and inserts must include the shard key, so from that perspective, the order may matter, particularly from a performance perspective - a more efficient order based on your query patterns will generally be a good idea. It may also be a good idea for data distribution, but really your question is a little vague.

Do a little reading of the links above, take a look at the other threads on the subject, and then ask more specific questions - if you have a proposed schema and data usage description, even better.