0

我是 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)) 的成员

这样做的正确方法是什么?

4

1 回答 1

1

这是您代码上的一个小错字

ConnectionPoolSettings.Builder.maxSize(100)

应该

ConnectionPoolSettings.builder().maxSize(100)

带有 Block 的代码如下所示:

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()
于 2019-10-30T16:24:37.117 回答