我想将mongoOptions添加到MongoClient基本上我想添加ConnectionPerHost值,默认值是10我想将它增加到20 但我在使用两种不同方式尝试的代码中出现错误
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")
方法1
val options=MongoClientOptions.apply( connectionsPerHost=20 )
val connectionMongo = MongoConnection(SERVER).addOption(options.getConnectionsPerHost)//returning Unit instead of MongoClient
val collectionMongo = connectionMongo(DATABASE)("testdb")
在最后一行Unit does not take parameters
方法2
val mongoOption=MongoClientOptions.builder()
.connectionsPerHost(20)
.build();
在MongoClientOptions.builder()
行
value builder is not a member of object com.mongodb.casbah.MongoClientOptions
-
我想将connectionsPerHost值设置为20,请帮助正确的方法执行此操作
答案 0 :(得分:1)
这似乎有效。
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")