Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-4344

server hostname is always 127.0.0.1 if MongoClient is initialized by uri "mongodb://user:pass@hostname:port/db?replicaSet=rs0"

    • Type: Icon: Bug Bug
    • Resolution: Works as Designed
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Monitoring

      If connectionUri contains replicaSet, client bad resolved server hosts.

      Follow simple code:

          String uri = "mongodb://user:password@182.18.4.3:27017/dbname?replicaSet=rs0";
          MongoClient client = MongoClients.create(uri);
          MongoDatabase dbTest = client.getDatabase("test");
          System.out.println(dbTest.listCollectionNames().first());
      

      .. throws exception (look address: address=127.0.0.1:27019):

      Exception in thread "main" com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting for a server that matches com.mongodb.client.internal.MongoClientDelegate$1@747f281. Client view of cluster state is {type=REPLICA_SET, servers=[{address=127.0.0.1:27019, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.ConnectException: Connection refused}}, {address=127.0.0.1:27018, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.ConnectException: Connection refused}}, {address=127.0.0.1:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.ConnectException: Connection refused}}]
      	at com.mongodb.internal.connection.BaseCluster.createTimeoutException(BaseCluster.java:405)
      	at com.mongodb.internal.connection.BaseCluster.selectServer(BaseCluster.java:118)
      	at com.mongodb.internal.connection.AbstractMultiServerCluster.selectServer(AbstractMultiServerCluster.java:50)
      	at com.mongodb.client.internal.MongoClientDelegate.getConnectedClusterDescription(MongoClientDelegate.java:139)
      	at com.mongodb.client.internal.MongoClientDelegate.createClientSession(MongoClientDelegate.java:94)
      	at com.mongodb.client.internal.MongoClientDelegate$DelegateOperationExecutor.getClientSession(MongoClientDelegate.java:276)
      	at com.mongodb.client.internal.MongoClientDelegate$DelegateOperationExecutor.execute(MongoClientDelegate.java:176)
      	at com.mongodb.client.internal.MongoIterableImpl.execute(MongoIterableImpl.java:135)
      	at com.mongodb.client.internal.MongoIterableImpl.iterator(MongoIterableImpl.java:92)
      	at com.mongodb.client.internal.MongoIterableImpl.first(MongoIterableImpl.java:103)
      	at com.mongodb.client.internal.MappingIterable.first(MappingIterable.java:50)
      	at test.main(test.java:11)
      
      

            Assignee:
            ross@mongodb.com Ross Lawley
            Reporter:
            pavol.slany@annotation.sk Pavol Slany
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: