1

Lets imagine I have two mongodb sharded collection: likes & comments.

Both collections are sharded, both collections have userId as a sharded key.

Lets imagine that likes collection is huge and comments collection is small. I have 10 shards in total, let's name them shard A to shard G.

Can I assume that if some particular user's likes are in shard A, then his comments will be in shard A as well?

So what I want to achieve is to have any particular user's data in the same shard. Other user's likes may be in shard C, then his comments should be in shard C as well.

Is it possibly to configure MongoDB? ( or it's the way how it's working by default? )

1

Is it possibly to configure MongoDB? ( or it's the way how it's working by default? )

Yes, if you want to control data location, you have to use Zones. Follow this link for a better explanation on how to do it: https://docs.mongodb.com/manual/tutorial/sharding-segmenting-shards/ .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.