Hi
I set up Mongo 4.0.2 for linux server. The server hostname is dbaMongoServer.org.
/etc/hosts content:
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.10.10 dbaMongoServer
As you can see the hostname established in /etc/hosts file is not the same for server hostname
Then I changed the mongod.conf to establish it as replicaset and I executed the following commands in mongoshell:
rs.initialize()
rs.add("192.168.10.10:27017").
One test application that connects to MongoDB and it started to faill. This application connects by IP address, not by hostname database server. These are the following messages from application log:
2022-11-28 08:54:53.848 INFO 14720 --- [XNIO-1 task-2] org.mongodb.driver.connection Closed connection [connectionId{localValue:3695}] to dbaMongoServer.org:27017 because there was a socket exception raised by this connection.
2022-11-28 08:54:53.850 ERROR 14720 --- [XNIO-1 task-2] p.g.r.services.ValidateService org.springframework.dao.DataAccessResourceFailureException: dbaMongoServer.org; nested exception is com.mongodb.MongoSocketException: dbaMongoServer.org
at org.springframework.data.mongodb.core.MongoExceptionTranslator.translateExceptionIfPossible(MongoExceptionTranslator.java:90)
at org.springframework.data.mongodb.core.MongoTemplate.potentiallyConvertRuntimeException(MongoTemplate.java:2774)
```
```
Caused by: com.mongodb.MongoSocketException: dbaMongoServer.org
at com.mongodb.ServerAddress.getSocketAddress(ServerAddress.java:188)
I fixed the /etc/hosts changing its third line as follows:
192.168.10.10 dbaMongoServer.org
The application keeps failling.
After that, I checked the replicaset configuration by db.conf(), I realized the member host was changed for itself from IP address to hostname.
"members" : [
{
"_id" : 0,
"host" : "dbaMongoServer.org:27017",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
}
],
The question is why the replica set member host changed for itself from server IP address to hostname?