Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

This is a pretty basic question but I can't find any answers on it. I know you use mongos to interface with a sharded collection. However, if I have a replica set which is not sharded how do I set up mongos so that my application can use both the primary and secondaries in that set? Is it even necessary to use mongos or will having my application's mongo driver (php in this case) connect to one server in the set have it automatically enumerate the other members in the set and connect to them as well?

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

You can connect to a replica set directly from the driver, a mongos is not required unless you are running in a sharded environment. The drivers generally use the isMaster command to determine the state of the set and will send commands to the primary and the secondary as appropriate (depending on the read preferences set, if you are using the latest versions). The drivers will also handle the automatic failover if the primary goes down (with a small delay of course).

Once some people try sharding, they prefer connecting to the mongos in general and letting it manage the communications back to the sets as you can see from this request. For now, to use mongos in this way, you need to have the minimum parts of the sharded environment configured, even if you just have (in effect) one shard.

Also, occasionally people will know that they are going to have to shard in the future and start with one shard in anticipation of that future need so that they don't need to do anything other than add a shard to the config.

In general, the main pre-requisite to have mongos run is the config database (and hence your config servers) up and running. The connection string that you pass to the mongos will be a list of those config servers (and should be the same on every mongos you start) and at least one (of the three) will have to be up and healthy for the mongos to function.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.