简体   繁体   English

mongo-scala-driver:如何在 MOngoClient 设置中添加连接池大小

[英]mongo-scala-driver :how to add connection pool size in MOngoClient Settings

i am new to mongo scala driver i am trying to add connection pool size when initiating a mongo instance i am doing it something like this我是 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)

value maxSize is not a member of object com.mongodb.connection.ConnectionPoolSettings.Builder [error].applyToConnectionPoolSettings(ConnectionPoolSettings.Builder.maxSize(100))值 maxSize 不是 object com.mongodb.connection.ConnectionPoolSettings.Builder [错误].applyToConnection.Builder10ConnectionPoolSettings 的成员

what is the right way to do this?这样做的正确方法是什么?

It is a small typo on your code这是您代码上的一个小错字

ConnectionPoolSettings.Builder.maxSize(100) ConnectionPoolSettings.Builder.maxSize(100)

should be应该

ConnectionPoolSettings.builder().maxSize(100) ConnectionPoolSettings.builder().maxSize(100)

The code with the Block would look like this:带有 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()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用mongo-scala-driver 2.1.0运行我的第一个MongoClient Scala代码时出现错误 - Errors when running my first MongoClient scala code with mongo-scala-driver 2.1.0 mongo-scala驱动程序交易示例 - Example of mongo-scala-driver transaction mongo-scala驱动程序是否支持GridF? - Does mongo-scala-driver support GridFs? 使用akka-http和mongo-scala驱动程序 - Work with akka-http and mongo-scala-driver 使用 mongo-scala-driver 在 Scala 中打印来自 Mongodb 的查询结果 - Printing query results from Mongodb in Scala using mongo-scala-driver Mongo-Scala-Driver:CodecConfigurationException:找不到类immutable.Document的编解码器 - Mongo-Scala-Driver: CodecConfigurationException: can't find a codec for class immutable.Document Mongo连接池(更改连接池的大小) - Mongo Connection Pooling(Changing the size of connection pool) 如何从MongoClient获取连接字符串中指定的Mongo数据库,Java - How to get the Mongo database specified in connection string from MongoClient, Java 如何使用 mongo .net 驱动程序获取客户端上的当前连接池占用率? - How to get current connection pool occupancy on client using mongo .net driver? mongodb scala驱动程序casbah是否自动管理连接池 - Does mongodb scala driver casbah manage connection pool automatically
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM