#Mongodb doesn t connect to my cluster in spring boot

1 messages · Page 1 of 1 (latest)

coral mirage
#

Mongodb doesn t connect to my cluster in spring boot instead is connecting to my local cluster 27017

open deltaBOT
#

<@&987246584574140416> please have a look, thanks.

coral mirage
#

here is what spring boots reports:

#

com.mongodb.MongoSocketOpenException: Exception opening socket
    at com.mongodb.internal.connection.SocketStream.lambda$open$0(SocketStream.java:85) ~[mongodb-driver-core-5.6.2.jar:na]
    at java.base/java.util.Optional.orElseThrow(Optional.java:403) ~[na:na]
    at com.mongodb.internal.connection.SocketStream.open(SocketStream.java:85) ~[mongodb-driver-core-5.6.2.jar:na]
    at com.mongodb.internal.connection.InternalStreamConnection.open(InternalStreamConnection.java:233) ~[mongodb-driver-core-5.6.2.jar:na]
    at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitor.setupNewConnectionAndGetInitialDescription(DefaultServerMonitor.java:282) ~[mongodb-driver-core-5.6.2.jar:na]
    at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitor.lookupServerDescription(DefaultServerMonitor.java:253) ~[mongodb-driver-core-5.6.2.jar:na]
    at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitor.run(DefaultServerMonitor.java:203) ~[mongodb-driver-core-5.6.2.jar:na]
Caused by: java.net.ConnectException: Connection refused
    at java.base/sun.nio.ch.Net.pollConnect(Native Method) ~[na:na]
    at java.base/sun.nio.ch.Net.pollConnectNow(Net.java:672) ~[na:na]
    at java.base/sun.nio.ch.NioSocketImpl.timedFinishConnect(NioSocketImpl.java:547) ~[na:na]
    at java.base/sun.nio.ch.NioSocketImpl.connect(NioSocketImpl.java:602) ~[na:na]
    at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:327) ~[na:na]
    at java.base/java.net.Socket.connect(Socket.java:633) ~[na:na]
    at com.mongodb.internal.connection.SocketStreamHelper.initialize(SocketStreamHelper.java:76) ~[mongodb-driver-core-5.6.2.jar:na]
    at com.mongodb.internal.connection.SocketStream.initializeSocket(SocketStream.java:104) ~[mongodb-driver-core-5.6.2.jar:na]```
open deltaBOT
# coral mirage ```2026-01-29T15:42:15.614+02:00 INFO 10173 --- [backend] [localhost:27017] org...

Detected code, here are some useful tools:

[WARNING] The code couldn't end properly...

Problematic source code:

2026-01-29T15:42:15.614+02:00  INFO 10173 --- [backend] [localhost:27017] org.mongodb.driver.cluster               : Exception in monitor thread while connecting to server localhost:27017

com.mongodb.MongoSocketOpenException: Exception opening socket
    at com.mongodb.internal.connection.SocketStream.lambda$open$0(SocketStream.java:85) ~[mongodb-driver-core-5.6.2.jar:na]
    at java.base/java.util.Optional.orElseThrow(Optional.java:403) ~[na:na]
    at com.mongodb.internal.connection.SocketStream.open(SocketStream.java:85) ~[mongodb-driver-core-5.6.2.jar:na]
    at com.mongodb.internal.connection.InternalStreamConnection.open(InternalStreamConnection.java:233) ~[mongodb-driver-core-5.6.2.jar:na]
    at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitor.setupNewConnectionAndGetInitialDescription(DefaultServerMonitor.java:282) ~[mongodb-driver-core-5.6.2.jar:na]
    at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitor.lookupServerDescription(DefaultServerMonitor.java:253) ~[mongodb-driver-core-5.6.2.jar:na]
    at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitor.run(DefaultServerMonitor.java:203) ~[mongodb-driver-core-5.6.2.jar:na]
Caused by: java.net.ConnectException: Connection refused
    at java.base/sun.nio.ch.Net.pollConnect(Native Method) ~[na:na]
    at java.base/sun.nio.ch.Net.pollConnectNow(Net.java:672) ~[na:na]
    at java.base/sun.nio.ch.NioSocketImpl.timedFinishConnect(NioSocketImpl.java:547) ~[na:na]
    at java.base/sun.nio.ch.NioSocketImpl.connect(NioSocketImpl.java:602) ~[na:na]
    at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:327) ~[na:na]
    at java.base/java.net.Socket.connect(Socket.java:633) ~[na:na]
    at com.mongodb.internal.connection.SocketStreamHelper.initialize(SocketStreamHelper.java:76) ~[mongodb-driver-core-5.6.2.jar:na]
    at com.mongodb.internal.connection.SocketStream.initializeSocket(SocketStream.java:104) ~[mongodb-driver-core-5.6.2.jar:na]```
Cause:
The code doesn't compile:
';' expected
not a statement
';' expected
not a statement
';' expected
not a statement
';' expected
not a statement
';' expected
not a statement
';' expected
';' expected
';' expected
'(' expected
')' expected
';' expected
variable declaration not allowed here
not a statement
';' expected
not a statement
';' expected
';' expected
';' expected
')' or ',' expected
not a statement
';' expected
not a statement
';' expected
';' expected
')' or ',' expected
not a statement
not a statement
';' expected
';' expected
')' or ',' expected
not a statement
';' expected
not a statement
';' expected
';' expected
')' or ',' expected
not a statement
';' expected
not a statement
';' expected
';' expected
')' or ',' expected
not a statement
';' expected
not a statement
';' expected
';' expected
')' or ',' expected
not a statement
';' expected
not a statement
';' expected
';' expected
')' or ',' expected
not a statement
';' expected
not a statement
';' expected
';' expected
not a statement
';' expected
';' expected
';' expected
')' or ',' expected
not a statement
not a statement
';' expected
not a statement
';' expected
';' expected
')' or ',' expected
not a statement
not a statement
';' expected
';' expected
')' or ',' expected
not a statement
not a statement
';' expected
';' expected
')' or ',' expected
not a statement
not a statement
';' expected
';' expected
')' or ',' expected
not a statement
not a statement
';' expected
';' expected
')' or ',' expected
not a statement
not a statement
';' expected
';' expected

## System out
[Nothing]
coral mirage
#

my aplication.proprierties:

#
spring.application.name=backend
server.port=7777
spring.data.mongodb.database=nutripro
spring.mongodb.embedded.storage.enabled=false```
#

and my connection in java:

#
private final UserRepo ur;

    public backend(UserRepo ur){
        this.ur = ur;
    }
@GetMapping("/nume/{name}")
    public String connectToDB(@PathVariable String name){
        return ur.findByName(name).map(User::getName)
                .orElse("Nu exista in Data Base");
    }```
umbral carbon
#

Hi @coral mirage , you have not told us the version of Spring Boot you are using and what libraries are included for your connection. This is an important detail but since you are using Spring Boot, I will assume you are using spring-boot-starter-data-mongodb.

coral mirage
umbral carbon
#

I think spring.mongodb.embedded.storage.enabled is incorrect and also a Spring Boot version 2 configuration.

coral mirage
#

so I watched this doc at the time but I didn t pay mush attention on this spring.data.mongodb.uri

#

so in doc is without .data

#

and now it s working!

#

THank you!

umbral carbon
#

No problem, happy it's working!