I'm creating a MEAN web project as my hobby. I have two mongoDB, one is in Japan and another one is in China. Can I configure my application to use different mongoDB based on location? For example, if the user is accessing from China, then the application should be able to choose mongoDB located in China. Is there any way to do this?
This can be achieved using tag based sharding or tag aware sharding. Basically, it works like this:
location: 'CHN'
or location: 'JPN'
CHN
and the Japanese shard with JPN
Now you can configure the shards that the Japanese shard should hold all documents with location: 'JPN'
and the Chinese shard to hold all documents to hold all documents with the location: CHN
with assigning those values to the accordingly tagged shards:
sh.addTagRange("database.collcetion", { location: "CHN" }, { location: "CHN" }, "CHN") sh.addTagRange("database.collcetion", { location: "JPN" }, { location: "JPN" }, "JPN")
Use location as your shard key.