【问题标题】:mongodb No server chosen by com.mongodb.async.client.ClientSessionHelper errormongodb No server selected by com.mongodb.async.client.ClientSessionHelper 错误
【发布时间】:2019-04-05 10:21:55
【问题描述】:

我想通过使用 scala 连接 mongodb,但出现错误:No server chosen by com.mongodb.async.client.ClientSessionHelper$1@8c3b9d from cluster description ClusterDescription{type=UNKNOWN, connectionMode=SINGLE, serverDescriptions=[ServerDescription{address=10.74.155.54:27017, type=UNKNOWN, state=CONNECTING}]}. Waiting for 30000 ms before timing out 这是一些版本信息: - MongoDB:4.0.3 - 斯卡拉:2.11.12

这是我的build.sbt 文件

libraryDependencies ++= Seq(
    "org.mongodb" % "bson" % "3.8.2",
    "org.mongodb" % "mongodb-driver-core" % "3.8.2",
    "org.mongodb" % "mongodb-driver-async" % "3.8.2",
    "org.mongodb.scala" %% "mongo-scala-driver" % "2.4.2",
    "org.mongodb.scala" % "mongo-scala-bson_2.11" % "2.4.2"
)

我的代码是这样的:

val mongoClient: MongoClient =  MongoClient("mongodb://xxxx/mydb")
val database: MongoDatabase = mongoClient.getDatabase("mydb")
val collection: MongoCollection[Document] = database.getCollection("test")

我只想联系standalone mongod,你能帮帮我吗?

谢谢!

【问题讨论】:

    标签: mongodb scala client driver


    【解决方案1】:

    您需要将 "mongodb://xxxx/mydb" 更改为 "mongodb://10.74.155.54" 并确保从您运行 Scala 应用程序的任何位置都可以访问数据库(无防火墙等)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-24
      • 1970-01-01
      • 2016-10-11
      • 2016-08-02
      • 1970-01-01
      相关资源
      最近更新 更多