MongoDB localhost connection
sujalsrivastava
FREEOP

3 months ago

2026-07-16T21:14:39.045Z INFO 1 --- [Chap-App-Backend] [ main] org.mongodb.driver.client : MongoClient with metadata {"driver": {"name": "mongo-java-driver|spring-boot|sync", "version": "5.8.0"}, "os": {"type": "Linux", "name": "Linux", "architecture": "amd64", "version": "6.18.15+deb13-cloud-amd64"}, "platform": "Java/Oracle Corporation/21.0.2+13-58"} created with settings MongoClientSettings{readPreference=primary, writeConcern=WriteConcern{w=null, wTimeout=null ms, journal=null}, retryWrites=true, retryReads=true, readConcern=ReadConcern{level=null}, credential=null, transportSettings=null, commandListeners=[], codecRegistry=ProvidersCodecRegistry{codecProviders=[ValueCodecProvider{}, BsonValueCodecProvider{}, DBRefCodecProvider{}, DBObjectCodecProvider{}, DocumentCodecProvider{}, CollectionCodecProvider{}, IterableCodecProvider{}, MapCodecProvider{}, GeoJsonCodecProvider{}, GridFSFileCodecProvider{}, Jsr310CodecProvider{}, JsonObjectCodecProvider{}, BsonCodecProvider{}, com.mongodb.client.model.mql.ExpressionCodecProvider@4cad79bc, com.mongodb.Jep395RecordCodecProvider@2c63762b, com.mongodb.KotlinCodecProvider@7a9eccc4, EnumCodecProvider{}]}, loggerSettings=LoggerSettings{maxDocumentLength=1000}, clusterSettings={hosts=[localhost:27017], srvServiceName=mongodb, mode=SINGLE, requiredClusterType=UNKNOWN, requiredReplicaSetName='null', serverSelector='null', clusterListeners='[]', serverSelectionTimeout='30000 ms', localThreshold='15 ms'}, socketSettings=SocketSettings{connectTimeoutMS=10000, readTimeoutMS=0, receiveBufferSize=0, proxySettings=ProxySettings{host=null, port=null, username=null, password=null}}, heartbeatSocketSettings=SocketSettings{connectTimeoutMS=10000, readTimeoutMS=10000, receiveBufferSize=0, proxySettings=ProxySettings{host=null, port=null, username=null, password=null}}, connectionPoolSettings=ConnectionPoolSettings{maxSize=100, minSize=0, maxWaitTimeMS=120000, maxConnectionLifeTimeMS=0, maxConnectionIdleTimeMS=0, maintenanceInitialDelayMS=0, maintenanceFrequencyMS=60000, connectionPoolListeners=[], maxConnecting=2}, serverSettings=ServerSettings{heartbeatFrequencyMS=10000, minHeartbeatFrequencyMS=500, serverMonitoringMode=AUTO, serverListeners='[]', serverMonitorListeners='[]'}, sslSettings=SslSettings{enabled=false, invalidHostNameAllowed=false, context=null}, applicationName='null', compressorList=[], uuidRepresentation=UNSPECIFIED, serverApi=null, autoEncryptionSettings=null, dnsClient=null, inetAddressResolver=null, contextProvider=null, timeoutMS=null}

2026-07-16T21:14:39.051Z INFO 1 --- [Chap-App-Backend] [localhost:27017] org.mongodb.driver.cluster : Exception in monitor thread while connecting to server localhost:27017

my application.properties is configured properly still the mongo db is connecting to localhost:27017

$10 Bounty

19 Replies

Railway
BOT

3 months ago

This thread has been opened as a bounty so the community can help solve it.

Status changed to Open Railway • 3 months ago


3 months ago

Why is it trying to connect to localhost? You sure you have used mongodb uri correctly?


mayori

Why is it trying to connect to localhost? You sure you have used mongodb uri correctly?

sujalsrivastava
FREEOP

3 months ago

yes i have checked it


sujalsrivastava
FREEOP

3 months ago

can u help me with this


3 months ago

Mongo host should be something like *.railway.internal or *.proxy.rlwy.net , make sure you have a variable for mongo uri that reference to the private mongo url ${MongoDB.MONGO_URL}


sujalsrivastava

can u help me with this

3 months ago

Can you share the snippet code that initializing the mongo connection? or if it's a public repo you can share the repo link here


sujalsrivastava
FREEOP

3 months ago


3 months ago

I'm checking now


3 months ago

Just a double check, do you have MONGO_URL defined on your backend variables on railway?


sujalsrivastava
FREEOP

3 months ago

yes


sujalsrivastava
FREEOP

3 months ago

image.png

Attachments


sujalsrivastava
FREEOP

3 months ago

did you find anything


3 months ago

I'm trying reproduce it right now


sujalsrivastava

![image.png](https://station-server.railway.com/attachments/att_01kxpe1wtbesjrj1b2k1myqgfk)

3 months ago

You haven't click deploy, it's on the top left on your screen


sujalsrivastava
FREEOP

3 months ago

no i did it multiple times


sujalsrivastava
FREEOP

3 months ago

it's not fixing


3 months ago

can you try log the env MONGO_URL to make sure the env was injected to your app


sujalsrivastava
FREEOP

3 months ago

Did you find anything wrong with my application.properties


3 months ago

(solution below)


3 months ago

Found the solution

You just have to change all spring.data.mongodb.* to spring.mongodb.* on your application.properties file

I added spring.mongodb.database to the properties because i got "Database must not empty" error while debugging

I also create a PR if you want to directly apply the changes from my test branch


Welcome!

Sign in to your Railway account to join the conversation.

Loading...