mongodb No server chosen by com.mongodb.async.client.ClientSessionHelper error

4,621 views
Skip to first unread message

chenzh...@gmail.com

unread,
Nov 1, 2018, 3:58:14 AM11/1/18
to mongodb-user
I want to connect mongodb by use scala , but I got error: `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
`
Here is some version info:
- mongodb: 4.0.3
- scala: 2.11.12

This is my `build.sbt` file

    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"
    )

I code like this:

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

I just want to connect a `standalone mongod`, Can you help me?

Thanks!

Wan Bachtiar

unread,
Nov 5, 2018, 1:29:16 AM11/5/18
to mongodb-user

but I got error: `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

Hi,

Could you make sure that you could reach the MongoDB server from the application instance ? Try using mongo shell to connect with the same URI to check.

The error message is generally related to an incorrect port number. For example, you only specified 10.74.155.54 without the port number, and the connection defaults to port number 27017. Please make sure this is the correct port number of the server.

This is my build.sbt file

This is likely not related to the error you’re getting, but you could just specify mongo-scala-driver as the dependency, and sbt should be able to pull in all of the other dependencies related to the driver.

libraryDependencies += "org.mongodb.scala" %% "mongo-scala-driver" % "2.4.2"

Regards,
Wan.

Reply all
Reply to author
Forward
0 new messages