According to this article: https://www.mongodb.com/blog/post/on-selecting-a-shard-key-for-mongodb. Assuming I have my schema as:
{
time_posted: ...,
userid: ...,
content: ...
}
The author mentions that if I frequently query the latest 10 articles from a certain user, I should set a compound key of time_posted
and user_id
.
But in my case, I only need to query the latest 10 articles from all users. Therefore I think I only need to set a single key time_posted
. I observed that by doing so the data are mostly inserted into 1 shard, and so Read Locality is improved, which is the desired effect.
However, according to https://docs.mongodb.org/v3.0/core/sharding-balancing/, Mongo will try to balance the data evenly among all the shards.
Balancing is the process MongoDB uses to distribute data of a sharded collection evenly across a sharded cluster. When a shard has too many of a sharded collection’s chunks compared to other shards, MongoDB automatically balances the chunks across the shards.
So my question are: must the data be evenly distributed among Mongo shards? and can I turn off the reblancerrebalancer since I don't need my data to be evenly distributed?