lkallas
lkallas

Reputation: 1406

Possible to specify to which mongoDB instance data is saved in a cluster?

I have a situation where I have to save UK citizen data to UK server and US citizen data to US server.

Customer (citizen) will fill a form in a web application, telling which country citizen he/she is. The storage is then chosen by a web application.

Is it possible to achieve something like this, or not?

And there also must be a possibility to query all citizens from both storages at once.

Upvotes: 0

Views: 16

Answers (1)

kevinadi
kevinadi

Reputation: 13775

What you need is called zone sharding in MongoDB. Essentially, given a shard key, you can tell MongoDB to store certain range of keys in certain part of the sharded cluster.

There is an example in Segmenting Data by Location which describes your use case.

Having said that, if you don't need to query all citizens very frequently, it's likely to be easier to deploy separate deployments under each jurisdiction, and perform the same query on each of them. This way, if you need the US servers to be maintained, it won't affect the UK operation.

Upvotes: 1

Related Questions