I have a java application that connects to mongoDB 4.0.2 replicaSet with one node (Primary). I upgraded the database to mongoDB 4.2.20. Even though, after making tests I decided to downgrade to 4.0.2. The properties file shows that application connects to database server through IP address.
Application properties file
host=192.168.10.10
user=test
password=testPass
dbAuth=admin
port=27017
Once downgraded it. We repeated the test for application and it couldn't connect to database. These are the error messages:
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.p.s.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)
at org.springframework.data.mongodb.core.MongoTemplate.executeFindMultiInternal(MongoTemplate.java:2684)
at org.springframework.data.mongodb.core.MongoTemplate.doFind(MongoTemplate.java:2427)
at org.springframework.data.mongodb.core.ExecutableFindOperationSupport$ExecutableFindSupport.doFind(ExecutableFindOperationSupport.java:214)
at org.springframework.data.mongodb.core.ExecutableFindOperationSupport$ExecutableFindSupport.all(ExecutableFindOperationSupport.java:157)
at org.springframework.data.mongodb.repository.query.AbstractMongoQuery.lambda$getExecution$1(AbstractMongoQuery.java:115)
...
Caused by: com.mongodb.MongoSocketException: dbaMongoServer.org
at com.mongodb.ServerAddress.getSocketAddress(ServerAddress.java:188)
at com.mongodb.internal.connection.SocketStreamHelper.initialize(SocketStreamHelper.java:64)
at com.mongodb.internal.connection.SocketStream.open(SocketStream.java:62)
at com.mongodb.internal.connection.InternalStreamConnection.open(InternalStreamConnection.java:126)
at com.mongodb.internal.connection.UsageTrackingInternalConnection.open(UsageTrackingInternalConnection.java:50)
Caused by: java.net.UnknownHostException: dbaMongoServer.org
at java.net.InetAddress.getAllByName0(InetAddress.java:1280)
at java.net.InetAddress.getAllByName(InetAddress.java:1192)
at java.net.InetAddress.getAllByName(InetAddress.java:1126)
at java.net.InetAddress.getByName(InetAddress.java:1076)
at com.mongodb.ServerAddress.getSocketAddress(ServerAddress.java:186)
...
The database server hostname is dbaMongoServer.org. So I had to add in /etc/hosts the IP address for dbaMongoServer.org in order it works.
What is happenning is it related to MongoDB server or something related to linux server? I've never had to add the hostname and IP address before. The properties file is showing the IP address, not a hostname. Even I've been reported that other applications couldn't connect to Mongo server I had to change it to /etc/hosts also.
What can I do?