mongo-scala-driver:如何在 MOngoClient 设置中添加连接池大小
mongo-scala-driver :how to add connection pool size in MOngoClient Settings
我是 mongo scala 驱动程序的新手 我正在尝试在启动 mongo 实例时添加连接池大小
我正在这样做
val settings: MongoClientSettings = MongoClientSettings.builder()
.applyToConnectionPoolSettings(ConnectionPoolSettings.Builder.maxSize(100))
.applyToClusterSettings(b => b.hosts(List(new ServerAddress("localhost")).asJava).description("Local Server"))
.build()
val mongoClient: MongoClient = MongoClient(settings)
值 maxSize 不是对象 com.mongodb.connection.ConnectionPoolSettings.Builder 的成员
[错误].applyToConnectionPoolSettings(ConnectionPoolSettings.Builder.maxSize(100))
正确的做法是什么?
这是您代码中的一个小错字
ConnectionPoolSettings.Builder.maxSize(100)
应该是
ConnectionPoolSettings.builder().maxSize(100)
带有块的代码如下所示:
val settings: MongoClientSettings = MongoClientSettings.builder()
.applyToConnectionPoolSettings((t: ConnectionPoolSettings.Builder) => t.applySettings(ConnectionPoolSettings.builder().maxSize(100).build()))
.applyToClusterSettings(b => b.hosts(List(new ServerAddress("localhost")).asJava).description("Local Server"))
.build()
我是 mongo scala 驱动程序的新手 我正在尝试在启动 mongo 实例时添加连接池大小 我正在这样做
val settings: MongoClientSettings = MongoClientSettings.builder()
.applyToConnectionPoolSettings(ConnectionPoolSettings.Builder.maxSize(100))
.applyToClusterSettings(b => b.hosts(List(new ServerAddress("localhost")).asJava).description("Local Server"))
.build()
val mongoClient: MongoClient = MongoClient(settings)
值 maxSize 不是对象 com.mongodb.connection.ConnectionPoolSettings.Builder 的成员 [错误].applyToConnectionPoolSettings(ConnectionPoolSettings.Builder.maxSize(100))
正确的做法是什么?
这是您代码中的一个小错字
ConnectionPoolSettings.Builder.maxSize(100)
应该是
ConnectionPoolSettings.builder().maxSize(100)
带有块的代码如下所示:
val settings: MongoClientSettings = MongoClientSettings.builder()
.applyToConnectionPoolSettings((t: ConnectionPoolSettings.Builder) => t.applySettings(ConnectionPoolSettings.builder().maxSize(100).build()))
.applyToClusterSettings(b => b.hosts(List(new ServerAddress("localhost")).asJava).description("Local Server"))
.build()