I'm trying to set up Zone Sharding on two MongoDB replica-sets.
I tried to follow the mongoDB docs and follow their guide, but I've unfortunately hit a wall and need some guidance:
This is what I've done so far:
I first created a test database called test1 (on the query router. After that I created my shard tags, one for each replica set.
sh.addShardTag("r0", "AS")
sh.addShardTag("r1", "EU")
Then I went on and enabled the sharding for my database and collection:
sh.enableSharding("test1")
sh.shardCollection("test1.users", { "code" : 1 } )
Finally I created my sharding rules. I want "code" values between 1->20 to be saved in shard1 (r0) and values between 20->40 to be saved in shard2(r2).
sh.addTagRange("test1.users", { code: "1" }, { code: "20" }, "AS")
sh.addTagRange("test1.users", { code: "20" }, { code: "40" }, "EU")
sh.status returns this and from my point of view it all looks fine:
{ "_id" : "test1", "primary" : "rs1", "partitioned" : true }
test1.users
shard key: { "code" : 1 }
unique: false
balancing: true
chunks:
rs0 1
rs1 3
{ "code" : { "$minKey" : 1 } } -->> { "code" : "100" } on : rs1 Timestamp(2, 1)
{ "code" : "1" } -->> { "code" : "20" } on : rs0 Timestamp(2, 0)
{ "code" : "20" } -->> { "code" : "40" } on : rs1 Timestamp(2, 2)
{ "code" : "40" } -->> { "code" : { "$maxKey" : 1 } } on : rs1 Timestamp(2, 3)
tag: AS { "code" : "1" } -->> { "code" : "20" }
tag: EU { "code" : "20" } -->> { "code" : "40" }
After I've set this up I went on and tried to push in some data to see if the data is being split up as I want.
for (i = 1; i < 40; i++) { db.users.insert({"code":i})}
However, all the data is being saved in to one shard, and the rules are totally ignored. I know I messed up somewhere, I just don't know where so all the help I can get is appreciated.
Thanks.