title: Multiple MongoDB connections to multiple mongo routers (mongos.exe)
body: <p>I have a system where there are multiple mongo shards (on large AWS instances), 3 mongo configs (on small AWS instances) and 3 mongo routers "mongos.exe" running (these are on the same instances as the app's i.e. 2 Tomcat's and 1 Java app).</p>
  
  <p>So my question is, should each app (e.g. tomcat 1) talk to the mongos.exe on that box, and only that, or should it also have a connection to the mongos.exe's on the other 2 boxes (I'm thinking no single point of failure here).</p>
  
  <p>In the mongo documentation <a href="http://docs.mongodb.org/ecosystem/tutorial/getting-started-with-java-driver/" rel="nofollow">http://docs.mongodb.org/ecosystem/tutorial/getting-started-with-java-driver/</a> you can connect to multiple mongo's using the following: -</p>
  
  <pre><code>// or, to connect to a replica set, with auto-discovery of the primary, supply a seed list of members
  MongoClient mongoClient = new MongoClient(Arrays.asList(
      new ServerAddress("localhost", 27017),
      new ServerAddress("localhost", 27018),
      new ServerAddress("localhost", 27019)));
  </code></pre>
  
  <p>Is this the way to go? If so, my last question is, what does Spring configuration look?  My spring config on the app's looks like this: -</p>
  
  <pre><code>&lt;mongo:mongo host="${db.host}" port="${db.port}"&gt;
      &lt;mongo:options threads-allowed-to-block-for-connection-multiplier="${db.threadsAllowedToBlockForConnectionMultiplier}"
                     connections-per-host="${db.connectionsPerHost}"
                     connect-timeout="${db.connectTimeout}"
                     max-wait-time="${db.maxWaitTime}"
                     auto-connect-retry="${db.autoConnectRetry}"
                     socket-timeout="${db.socketTimeout}"/&gt;
  &lt;/mongo:mongo&gt;
  
  &lt;mongo:db-factory dbname="${db.name}" mongo-ref="mongo" /&gt;
  </code></pre>
  
  <p>Any advice is much appreciated.</p>