MongoServerSelectionException: Unable to connect to any server that satisfies the selector

1,882 views
Skip to first unread message

shingh...@gmail.com

unread,
Apr 1, 2014, 12:07:48 PM4/1/14
to mongodb-ca...@googlegroups.com
Hi,

  I am using Casbah 2.7.0-RC1  to connect to a remote instance of MongoDB 2.4.9, which is part of a replicate set.

But I have the following exception.
 

com.mongodb.MongoServerSelectionException: Unable to connect to any server that satisfies the selector CompositeServerSelector{serverSelectors=[NoOpServerSelector{}, ReadPreferenceServerSelector{readPreference=primary}, LatencyMinimizingServerSelector{acceptableLatencyDifference=15, timeUnit=MILLISECONDS}]}

at com.mongodb.BaseCluster.getServer(BaseCluster.java:79)

at com.mongodb.DBTCPConnector.getServer(DBTCPConnector.java:649)

at com.mongodb.DBTCPConnector.access$300(DBTCPConnector.java:42)

at com.mongodb.DBTCPConnector$MyPort.getConnection(DBTCPConnector.java:508)

at com.mongodb.DBTCPConnector$MyPort.get(DBTCPConnector.java:456)

at com.mongodb.DBTCPConnector.innerCall(DBTCPConnector.java:287)

at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:272)

at com.mongodb.DBCollectionImpl.find(DBCollectionImpl.java:77)

at com.mongodb.DBCollectionImpl.find(DBCollectionImpl.java:60)

at com.mongodb.DBCollection.findOne(DBCollection.java:869)

at com.mongodb.DBCursor.one(DBCursor.java:677)

at com.mongodb.casbah.MongoCollectionBase$class.findOne(MongoCollection.scala:260)

at com.mongodb.casbah.MongoCollection.findOne(MongoCollection.scala:1109)

at com.adbrain.segment.store.casbah.CasbahSegmentDAO.getSegment(CasbahSegmentDAO.scala:87)



Everything works find if connect to a local instance of MongodDB.

I would be grateful for any suggestion to reolve the above.


Thanks in advance for any assistance !


Shing

shingh...@gmail.com

unread,
Apr 1, 2014, 12:12:40 PM4/1/14
to mongodb-ca...@googlegroups.com



  lazy private val servers =  HOST_PORT_PAIRS.map {case (host,port)  => new ServerAddress(host, port) }
    lazy private val credentials = MongoCredential.createMongoCRCredential(USER_ID, "admin", PASSWORD.toCharArray())

    lazy private val mongoClient = { val client = MongoClient(servers, List(credentials));                       
                             client.setWriteConcern(WriteConcern.Safe);                           
                             client}

    The set up give me the mentioned exception.
  If I have
     val client = MongoClient(servers.head, List(credentials));

  there is no exception.

Shing

shingh...@gmail.com

unread,
Apr 1, 2014, 4:48:39 PM4/1/14
to mongodb-ca...@googlegroups.com
In the remote instance of MongoDB (in a replicate set),   in the configuration of the replicate set,  the host is a simple host name. eg  myserver instead of the full domain name.
After setting the host to  the  full domain name, the mentioned exception disappeared.
 
The problem has nothing to do with Casbah.

Shing

Ross Lawley

unread,
Apr 1, 2014, 6:31:26 PM4/1/14
to mongodb-ca...@googlegroups.com
Hi Shing,

I'm glad you got it sorted - the stacktrace is confusing and masks the core issue that you identified - in that the driver wasn't able to connect to any server.

All the best,

Ross


--
You received this message because you are subscribed to the Google Groups "mongodb-casbah-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-casbah-u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

name     : "Ross  Lawley",

  title    : "Scala and Python Engineer",

  location : "London, UK",

  twitter  : ["@RossC0", "@MongoDB""@MongoDBInc"],

  facebook : ["MongoDB", "MongoDB, Inc."] }

Reply all
Reply to author
Forward
0 new messages