Search code examples
mongodbsharding

Can I shard Mongo base on IP address?


Instead of sharding base on the data, can I shard based on where the request (IP address) coming from?

Hmmm one trick I think of is the data itself contains IP address. Is there another way?


Solution

  • Yes, you'd need to include an IP address field in each document and include it in your shard key. Choosing a good shard key is quite a tricky thing to get right, it depends a lot on the shape of your data and how it'll be queried.

    Here's a good place to start: Choosing a Mongo Shard Key