mongodb com.mongodb.async.client.ClientSessionHelper错误未选择服务器

时间:2018-11-01 07:50:55

标签: mongodb scala client driver

我想通过使用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,您能帮我吗?

谢谢!

1 个答案:

答案 0 :(得分:0)

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