title: Mongo DB Canonical address does not match server address
body: <p>I am connecting my spring boot application with mongo db.</p>
  
  <p>The code is working fine on local environment where the db has a single node and not running in cluster mode.</p>
  
  <p>But when the db is running on staging environment with cluster mode and a single node and 1 replica set, the spring application shows the following error:</p>
  
  <pre><code>INFO  |  |  | 2019-04-18 12:43:25 | [cluster-ClusterId{value='5cb823951a734cea7f7eebe1', description='null'}-10.202.41.254:27017] com.mongodb.diagnostics.logging.SLF4JLogger - Canonical address educationelasticsearch-digital-v1-41-254:27017 does not match server address.  Removing 10.20.41.254:27017 from client view of cluster
  INFO  |  |  | 2019-04-18 12:43:25 | [cluster-ClusterId{value='5cb823951a734cea7f7eebe1', description='null'}-educationelasticsearch-digital-v1-41-254:27017] com.mongodb.diagnostics.logging.SLF4JLogger - Exception in monitor thread while connecting to server educationelasticsearch-digital-v1-41-254:27017
  com.mongodb.MongoSocketException: educationelasticsearch-digital-v1-41-254: nodename nor servname provided, or not known
      at com.mongodb.ServerAddress.getSocketAddress(ServerAddress.java:188) ~[mongodb-driver-core-3.8.2.jar:?]
      at com.mongodb.internal.connection.SocketStreamHelper.initialize(SocketStreamHelper.java:64) ~[mongodb-driver-core-3.8.2.jar:?]
      at com.mongodb.internal.connection.SocketStream.open(SocketStream.java:62) ~[mongodb-driver-core-3.8.2.jar:?]
      at com.mongodb.internal.connection.InternalStreamConnection.open(InternalStreamConnection.java:126) ~[mongodb-driver-core-3.8.2.jar:?]
      at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:117) [mongodb-driver-core-3.8.2.jar:?]
      at java.lang.Thread.run(Thread.java:748) [?:1.8.0_171]
  Caused by: java.net.UnknownHostException: educationelasticsearch-digital-v1-41-254: nodename nor servname provided, or not known
      at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method) ~[?:1.8.0_171]
      at java.net.InetAddress$2.lookupAllHostAddr(InetAddress.java:928) ~[?:1.8.0_171]
      at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1323) ~[?:1.8.0_171]
      at java.net.InetAddress.getAllByName0(InetAddress.java:1276) ~[?:1.8.0_171]
      at java.net.InetAddress.getAllByName(InetAddress.java:1192) ~[?:1.8.0_171]
      at java.net.InetAddress.getAllByName(InetAddress.java:1126) ~[?:1.8.0_171]
      at java.net.InetAddress.getByName(InetAddress.java:1076) ~[?:1.8.0_171]
      at com.mongodb.ServerAddress.getSocketAddress(ServerAddress.java:186) ~[mongodb-driver-core-3.8.2.jar:?]
      ... 5 more
  </code></pre>
  
  <p>In both the case, application properties are same except the change in IP of staging server in place of localhost:</p>
  
  <pre><code>spring.elasticsearch.education.hostname=localhost   // staging server IP
  spring.elasticsearch.education.scheme=http
  spring.elasticsearch.education.port=9200
  
  
  ###### Mongo properties ########
  spring.data.mongodb.host=localhost  //staging server ip
  spring.data.mongodb.port=27017
  spring.data.mongodb.database=ddddd
  spring.data.mongodb.authentication-database=admin
  spring.data.mongodb.username=root
  spring.data.mongodb.password=root
  spring.data.mongodb.repositories.enabled=true
  logging.level.org.springframework.data.mongodb.core.MongoTemplate=DEBUG
  </code></pre>
  
  <p>I checked <a href="https://stackoverflow.com/questions/41892411/mongodb-hostname-uri-configuration">this question</a> but not much resolution in this.</p>
  
  <p>Please suggest what's wrong here?</p>