سؤال

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.

هل كانت مفيدة؟

المحلول

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/

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top