I have a Spring boot application configured wih MongoDB.Everything worked just fine when working with mongodb on localhost.The problem is when i try to connect to mongodb on remote server i get “Exception opening socket” and “connect timed out”.
I already changed bind_ip = 127.0.0.1 to bind_ip = 0.0.0.0.
This is the config in my application.properties file:
spring.data.mongodb.uri=mongodb://user:password@remote_url/database_name
Is it a replica or a standalone DB?
What does you remote url look like
Sample from mongo doc
spring.data.mongodb.uri=mongodb://user:password@mongo1.example.com:12345,mongo2.example.com:23456/test
how can i identify if it’s a replica or a standalone ?
Can you access your remote db from shell?
You can use rs.status(),rs.conf() to know about your setup
Hi, did you ever solve the problem? I have the same issue. How did you fix it?
Are you using correct host & port?
Is your mongodb running with auth?
Is it standalone or replica
Check this link for various connect strings
Sorry for taking so long to respond. If I am using a URI, then I thought I’m not supposed to configure a host and port on the application,properties file? No it is not running with auth. Essentially, I have successfully connected to MongoDB Compass with no problems, but when I try to set up the applications.properties file to connect to MongoDB Atlas, I have errors. I get the exact same error: “Exception opening socket” and “connect timed out”. Do you have any advice on how to configure a Java Springboot application to connect to MongoDB Atlas if I have been trying the URI method, and I’ve enabled all IP’s to be able to access my database.
Can you connect by shell?
What type of connect string are you using in URI?
SRV or long form(old style)
With long form you have to use port
Check our forum threads.Many examples given for application.properties
Hello, thanks for your help. I finally figured it out. The wifi was the problem, and it works on my personal mobile hotspot.
Hi , sorry to post the subject again but I have a problem with the host name ex: cluster0.e4xb04k.mongodb.net
I’m using spring boot to connect, and the error says hostname not found?
I am working on multi-tenant application so i have multiple database now i want to specify a database in the model.
Anyone have any idea about this how to do?
Check your MongoDB server log file for any relevant message or error related information.
john_sam
(John Sam)
14
make sure that MongoDB server is configured to allow the external connection by firewall setting