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 at 8:29
  • Okay .. i have deployed using marketplace console.cloud.google.com/marketplace/details/… . 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 at 8:40
  • Have a look at this question - it could be helpful – Serhii Rohoza Apr 10 at 9:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.