1

i want to add mongoOptions to MongoClient basically i want to add ConnectionPerHost value its default is 10 i want to increase it to 20
but i am getting errors in the code i have tried with two different ways

val SERVER:ServerAddress = {

val hostName=config.getString("db.hostname")

val port=config.getString("db.port").toInt
        new ServerAddress(hostName,port)
          }
val DATABASE:String   = config.getString("db.dbname")

method 1

val options=MongoClientOptions.apply( connectionsPerHost=20 )
val connectionMongo = MongoConnection(SERVER).addOption(options.getConnectionsPerHost)//returning Unit instead of MongoClient 
val collectionMongo = connectionMongo(DATABASE)("testdb")

getting error on last line Unit does not take parameters

method 2

val mongoOption=MongoClientOptions.builder()
                .connectionsPerHost(20)
                .build();

getting error on MongoClientOptions.builder() line

value builder is not a member of object com.mongodb.casbah.MongoClientOptions

-

i want to set connectionsPerHost value to 20 please help what is the right way to do this

swaheed
  • 3,671
  • 10
  • 42
  • 103

1 Answers1

1

This seems to be working.

val config = ConfigFactory.load();
val hostName = config.getString("db.hostname")
val port = config.getInt("db.port")

val server = new ServerAddress(hostName, port)
val database = config.getString("db.dbname")

val options = MongoClientOptions(connectionsPerHost = 20)
val connectionMongo = MongoClient(server, options) 
val collectionMongo = connectionMongo(database)("testdb")

Note that MongoConnection is deprecated.

mfirry
  • 3,634
  • 1
  • 26
  • 36