Question

I'am going to move my 500 millions rows table from postgresql to sharded collection in MongoDB. I am in the middle of choosing proper sharding key.

Table Posts(id, users_id,title,content). Each post belongs to specified user. Users have from 100 to 1 million posts.

Is it possible to set sharding key as modulo from users_id (e.g. users_id % 128)? I query database by WHERE users_id.

Is it possible? Is it good idea? I am asking, because when i haven't found anything about using module in shadring key.

Was it helpful?

Solution

You probably want your shard key to be {users_id: 'hashed'}, this way MongoDB will take care of the distribution for you. Read more here: http://docs.mongodb.org/manual/tutorial/shard-collection-with-a-hashed-shard-key/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top