0

I have a spring MVC application and I am connecting it to MongoDB cluster

This is in the application.properties file

mongodb.url=mongodb://userName:Password@xx.xx.x.xx:27017,xx.xx.x.xx:27017,xx.xx.x.xx:27017/?authSource=admin

The cluster is deployed on GCP with one primary and 2 secondary servers. However, after deployment when I hit the API to get the data I get an error​

{java.net.UnknownHostException: mongodb-3-arbiters-vm-0}}, {address=mongodb-3-servers-vm-1:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketException: mongodb-3-servers-vm-1}, caused by {java.net.UnknownHostException: mongodb-3-servers-vm-1}}

The external IPs are getting mapped to the server name on the GCP dashboard. xx.xx.xx.xx:27017 to mongodb-3-servers-vm-1:27017, hence resulting in unknown host exception. what to do to avoid that ?

  • Please provide more details: 1. Have you deployed your cluster from Marketplace? 2. Do you have firewall rules to allow connections to your cluster? 3. "The external IPs are getting mapped to the server name on the GCP dashboard" please explain. 4. Where your spring MVC application located (gcp, other cloud or on-premises)? – Serhii Rohoza Apr 10 '20 at 08:29
  • Okay .. i have deployed using marketplace https://console.cloud.google.com/marketplace/details/click-to-deploy-images/mongodb . Next the firewall rules are all open .. i am able to connect via mongo shell from anywhere . Spring application was deployed on AWS but since the cluster is accessible from anywhere connection should not be an issue . @SerhiiRohoza So to connect to mongodb cluster i have entered the above url in the question with external IPs that gcp providies like 65.43.222.11 etc . So while hitting the spring api to get data i am getting 500 error with the above mentioned error – Pulkit Kedia Apr 10 '20 at 08:40
  • Have a look at this [question](https://stackoverflow.com/questions/41892411/mongodb-hostname-uri-configuration) - it could be helpful – Serhii Rohoza Apr 10 '20 at 09:05

0 Answers0