Mongo Connection Pooling(Changing the size of connection pool)

neoeahit picture neoeahit · Jul 3, 2014 · Viewed 12.7k times · Source

How to change the mongo connection pool size?

I have seen it is 100 by default. Is there a way to change this value?

I dont want to do it via spring, is there a way to configure it via MongoClient?

There is an option i see about mongoClientOptions but i dont see options to set connection pool

Answer

evanwong picture evanwong · Jul 3, 2014

You can build your own MongoClient instance using the MongoClientOptions.Builder.

MongoClientOptions.Builder builder = new MongoClientOptions.Builder();
MongoClientOptions options = builder.connectionsPerHost(10).build();
MongoClient client = new MongoClient(listOfServers, options);