2
votes

I am moving from a single mongodb instance to a sharded cluster with 3 replica sets, 3 config servers and 1 mongos instance. Each replica set in turn has three mongod instances.

I'm looking for high availability when I am adding documents to the collection. What should I connect to from my Java program? Should I connect to mongos or mongod from any replica set?

Can you please let me know ?

Thanks.

2

2 Answers

2
votes

In sharded environment, your application(s) should always connect to mongos instance(s).

From your application's perspective mongos instance behaves as any other MongoDB instance.

Even if you have a non-sharded database or a collection that resides on a single shard, it's recommended that you use mongos for all operations (even if those operations don't impact sharded data).

You can read more details on Sharded Cluster Query Routing man pages.

1
votes

You should connect to the mongos and let it route your requests as appropriate.