0
votes

Consider we have 3 node N1, N2, N3.

  1. On Node 1 mongod instance with port 26000 with replica set
    rs0(Primary) mongod instance with port 26001 with replica set
    rs1(Arbiter) mongod instance with port 26002 with replica set
    rs2(Secondary)
  2. On Node 2 mongod instance with port 26000 with replica set rs0(Secondary) mongod instance with port 26001 with replica set rs1(Primary) mongod instance with port 26002 with replica set rs2(Arbiter)
  3. On Node 3 mongod instance with port 26000 with replica set rs0(Secondary) mongod instance with port 26001 with replica set rs1(Arbiter) mongod instance with port 26002 with replica set rs2(Primary)

Now we have 3 standalone shards with replication sets each have one secondary and Arbiter On Node 1, we start configserver on port 27019, next we also start one mongos instance using this configsvr instance , and then add each shard to it. Now my question is my java code which inserts document should talk to this mongos instance for inserting documents, or i can insert them directly in any shared through primary instance they will automatically split the data accordingly.

2

2 Answers

1
votes

This is the basic concept of sharding - and it is not at all influenced by what machines are running which processes.

You should only have your application connect to mongos process. Under no circumstances should you be manipulating data directly on any shard/primary.

The only time you would be connecting to shards directly is for various administrative maintenance tasks. Your application should not even know what hosts or ports they are running on - it only needs to know how to connect to mongos process.

1
votes

First of all it is necessary that your config server is running. And after that you should have connection of your application with the mongos server. You should only connect to the mongos server and all the data should be populated from it only.

If you insert data to the shard servers it will be not be distributed and would stay on that servers only.