I have some very basic questions regarding shard key.
In our application, we are creating _id fields from a coarse grained attribute -country and a per country monotonically increasing sequence number eg IN_1. As per several online references and books (eg http://www.kchodorow.com/blog/2011/01/04/how-to-choose-a-shard-key-the-card-game/), it is better to have a compound shard key - coarse grained key + search key. We also have a country attribute in the shard key and have an index on that.
Most, if not all of our queries on these collections are going to be country search based or _id based.
What would be the best choice for a shard key
- just _id - since ctry is already baked into it - will it make queries starting with ctry slow?
- {ctry: 1, _id: 1} - but part of my _id is monotonically increasing sequence.
- {ctry: 1, _id: hashed} - Promises both read locality and write distribution. Is this supported by MongoDB?
- just {_id: hashed} - will it make queries starting with ctry slow?
I am inclined to using the option 3- but is that possible - it is not very clear from MongoDB docs.