<p>We have 4 mongoDB servers of which the first one is currently the primary with 3 replicas. If I specify all 4 servers in the connection string it fails to connect at all, but if I just specify the first one it connects fine. This is bad because if the first server fails, it will not be able to connect.</p>
<p>This works:
mongodb://login:password@server1:27017/admin?readPreference=Primary</p>
<p>This does NOT work:
mongodb://login:password@server1:27017,server2:27017,server3:27017,server4:27017/admin?readPreference=Primary</p>
<p>Exception:
A timeout occured after 30000ms selecting a server using CompositeServerSelector{ Selectors = WritableServerSelector, LatencyLimitingServerSelector{ AllowedLatencyRange = 00:00:00.0150000 } }. Client view of cluster state is { ClusterId : &quot;1&quot;, ConnectionMode : &quot;Automatic&quot;, Type : &quot;ReplicaSet&quot;, State : &quot;Connected&quot;, Servers : [{ ServerId: &quot;{ ClusterId : 1, EndPoint : &quot;Unspecified/server1:27017&quot; }&quot;, EndPoint: &quot;Unspecified/server1:27017&quot;, State: &quot;Disconnected&quot;, Type: &quot;Unknown&quot;, HeartbeatException: &quot;MongoDB.Driver.MongoConnectionException: An exception occurred while opening a connection to the server.</p>
<p>The service trying to connect runs on Kube.</p>
<p>Any idea why this would be?</p>

jman
<p>you need to add the mode to the connection string: replicaSet=myRepl</p>
