[JAVA-4344] server hostname is always 127.0.0.1 if MongoClient is initialized by uri "mongodb://user:pass@hostname:port/db?replicaSet=rs0" Created: 12/Oct/21 Updated: 27/Oct/23 Resolved: 23/Oct/21 |
|
| Status: | Closed |
| Project: | Java Driver |
| Component/s: | Monitoring |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Pavol Slany | Assignee: | Ross Lawley |
| Resolution: | Works as Designed | Votes: | 0 |
| Labels: | external-user | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Description |
|
If connectionUri contains replicaSet, client bad resolved server hosts. Follow simple code:
.. throws exception (look address: address=127.0.0.1:27019):
|
| Comments |
| Comment by Pavol Slany [ 25/Oct/21 ] |
|
Dear Ross Lawley, thank you very much for your really useful information. It helped me to understand, why host and port was different. My test was created in docker image and addresses in image and hosted computer are diferrent. Sorry for this ticket. Best regards |
| Comment by Ross Lawley [ 12/Oct/21 ] |
|
Thank you for reaching out. As this sounds like a support issue, I wanted to give you some resources to get this question answered more quickly in future:
Just in case you have already opened a support case and are not receiving sufficient help, please let me know and I can facilitate escalating your issue. The driver monitors replica set changes top provide resilience and allow for targeted reads. To do that the driver uses the replica set configuration as the source of truth. So in this case, its connecting using the host in your MongoDB connection string, then it is using the replica set configuration information so that it can monitor and connect to the other replica set nodes. I believe your replica set nodes have been configured to use local ips rather than an ip that is accessible to your application. In short the hostname name in your replica set configuration must be resolvable for every host in the replica set as well as to the application / MongoDB Java Driver. I hope that helps, Ross Lawley |