title: Setting Mongodb Connection Pool Options via mongo-java-driver Java API
body: <p>Using Morphia and mongo-java-driver, I'm connecting to a mongo server:</p>
  
  <pre><code>MongoClientOptions.Builder builder = MongoClientOptions.builder();
          builder.sslEnabled(true);
          builder.sslInvalidHostNameAllowed(true);
          builder.maxConnectionIdleTime(0);
          MongoClientOptions sslOptions = builder.build();
  
          MongoClient mongoClient = new MongoClient(serverAddressList, Arrays.asList(mongoCredential), sslOptions);
  </code></pre>
  
  <p>Where serverAddressList is the <strong>host:port</strong> list and mongoCredential using kerberos auth are created as:</p>
  
  <pre><code>MongoCredential mongoCredential = MongoCredential.createGSSAPICredential("user@REALM.COM");
  </code></pre>
  
  <p>I want to setup a custom Connection Pool Parameters using:</p>
  
  <ol>
  <li>maxPoolSize</li>
  <li>minPoolSize</li>
  <li>maxIdleTimeMS etc.</li>
  </ol>
  
  <p>To achieve this I found <strong>ConnectionPoolSettings.Builder</strong> and <strong>com.mongodb.connection.ConnectionPoolSettings</strong> Classes.</p>
  
  <p>I searched a sample code <a href="https://www.programcreek.com/java-api-examples/?code=frederikhappel/activecheck/activecheck-master/activecheck-reporter-mongodb/src/main/java/org/activecheck/plugin/reporter/mongodb/MongodbReporter.java" rel="nofollow noreferrer">here</a>:</p>
  
  <pre><code>ConnectionPoolSettings connectionPoolSettings = ConnectionPoolSettings
                  .builder()
                  .minSize(MIN_MONGO_POOL_SIZE)
                  .maxSize(MONGO_POOL_SIZE)
                  .build();
          MongoClientSettings settings = MongoClientSettings
                  .builder()
                  .readPreference(MONGO_READ_PREFERENCE)
                  .credentialList(credentialsList).clusterSettings(clusterSettings)
                  .connectionPoolSettings(connectionPoolSettings).build();
  </code></pre>
  
  <p>Can someone please suggest a way of applying these settings to get an Instance of MongoClient ?</p>
  
  <p>Libraries which are being used:</p>
  
  <pre><code>dependencies {
      compile 'org.mongodb:mongodb-driver-sync:3.4.3'
    }
  </code></pre>