Error connecting with scala driver

358 views
Skip to first unread message

Josh Kim

unread,
Oct 18, 2016, 5:49:11 PM10/18/16
to mongodb-user
I'm trying to connect to a mongodb instance running locally with the official scala driver. It is not part of a replica set and there is absolutely nothing fancy going on with the setup.  As soon as I get a collection it returns an error message and I can not find anything useful anywhere (google, stackoverflow, etc).  I have no problems connecting to the mongo shell through a client.

Does anybody know what's going on here?

val _mongoClient = MongoClient("mongodb://localhost")
val _database = _mongoClient.getDatabase("db")
val _collection = _database.getCollection("xyz")

INFO  org.mongodb.driver.cluster - Cluster created with settings {hosts=[localhost:27017], mode=SINGLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500}
INFO  org.mongodb.driver.cluster - Exception in monitor thread while connecting to server localhost:27017
com.mongodb.MongoException: java.io.IOException: ConnectEx failed
at com.mongodb.connection.InternalStreamConnection.open(InternalStreamConnection.java:125)
at com.mongodb.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:128)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.io.IOException: ConnectEx failed
at sun.nio.ch.WindowsAsynchronousSocketChannelImpl.connect0(Native Method)
at sun.nio.ch.WindowsAsynchronousSocketChannelImpl.access$200(WindowsAsynchronousSocketChannelImpl.java:43)
at sun.nio.ch.WindowsAsynchronousSocketChannelImpl$ConnectTask.run(WindowsAsynchronousSocketChannelImpl.java:235)
at sun.nio.ch.WindowsAsynchronousSocketChannelImpl.implConnect(WindowsAsynchronousSocketChannelImpl.java:382)
at sun.nio.ch.AsynchronousSocketChannelImpl.connect(AsynchronousSocketChannelImpl.java:209)
at com.mongodb.connection.AsynchronousSocketChannelStream.openAsync(AsynchronousSocketChannelStream.java:79)
at com.mongodb.connection.AsynchronousSocketChannelStream.open(AsynchronousSocketChannelStream.java:61)
at com.mongodb.connection.InternalStreamConnection.open(InternalStreamConnection.java:114)
... 2 common frames omitted
INFO  org.mongodb.driver.cluster - No server chosen by ReadPreferenceServerSelector{readPreference=primary} from cluster description ClusterDescription{type=UNKNOWN, connectionMode=SINGLE, all=[ServerDescription{address=localhost:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoException: java.io.IOException: ConnectEx failed}, caused by {java.io.IOException: ConnectEx failed}}]}. Waiting for 30000 ms before timing out
Exception in thread "main" com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting for a server that matches ReadPreferenceServerSelector{readPreference=primary}. Client view of cluster state is {type=UNKNOWN, servers=[{address=localhost:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoException: java.io.IOException: ConnectEx failed}, caused by {java.io.IOException: ConnectEx failed}}]
at com.mongodb.connection.BaseCluster.createTimeoutException(BaseCluster.java:369)
at com.mongodb.connection.BaseCluster.handleServerSelectionRequest(BaseCluster.java:283)
at com.mongodb.connection.BaseCluster.access$800(BaseCluster.java:51)
at com.mongodb.connection.BaseCluster$WaitQueueHandler.run(BaseCluster.java:450)
at java.lang.Thread.run(Thread.java:745)

Thanks so much.

Wan Bachtiar

unread,
Oct 23, 2016, 11:59:05 PM10/23/16
to mongodb-user

Caused by: java.io.IOException: ConnectEx failed

Does anybody know what's going on here?

Hi Josh,

Looking at your exception error log, it looks like an error related to Windows ConnectEx function.

I have no problems connecting to the mongo shell through a client.

Did you mean to say, that you are able to connect to mongod via the mongo shell client ?

If not, could you elaborate what did you mean by 'through a client' ?

 It is not part of a replica set and there is absolutely nothing fancy going on with the setup.

To clarify, do you have a standalone MongoDB instance running locally on the default port 27017 ?

Could you also provide the following relevant information:

Regards,

Wan.

Fred

unread,
Apr 16, 2018, 6:22:14 PM4/16/18
to mongodb-user
It's been a while since this was last updated, but I am having the same problem.

MongoDB Scala Driver version: 2.2
Scala Version: 2.12.5
Specific mongo db version: Version 3.4.14 (hosted on Mongo DB Atlas)
Specific OS Version: macOS High Sierra 10.13.4

Any help would be highly appreciated (I also asked a question on SO: https://stackoverflow.com/questions/49844715/unable-to-connect-to-mongodb-atlas-using-scala-driver)

Wan Bachtiar

unread,
Apr 18, 2018, 10:46:03 PM4/18/18
to mongodb-user

Any help would be highly appreciated I also asked a question on SO

Hi Fred,

Looks like your question has been answered on the StackOverflow link you provided.

For future reference, please open a new discussion thread. Although you may share the same general question on connecting using the Scala driver, it may be a different issue altogether. Also the original question was posted in 2016, there has been many changes/improvements since.

Kind regards,
Wan.

Reply all
Reply to author
Forward
0 new messages