Cannot connect to MongoDB with public URL

fedealconadaPRO

5 months ago

I have an app with a mongo service. 2 environements (staging and production). I've been using staging fine but, somehow, on the production environment, I can't connect to the database. Production is basically a clone of staging.

On Railway's UI, if I go to the "data" tab, I can see this:

  • Deployment Online

    This service has an active deployment

  • Required Variables

    This service has all the necessary variables that this UI uses to connect to the database.

  • Database Connection

On the last bullet, there's constantly a spinner.

If I try connecting through CLI using mongosh:
```
mongosh PUBLIC_URL

Connecting to: mongodb://<credentials>@HOST:PORT/?directConnection=true&appName=mongosh+2.3.2

MongoServerSelectionError: read ECONNRESET
```

Awaiting User Response

5 Replies

5 months ago

Hello,

You have the TCP Proxy port pointing to 5433, when Mongo listens on 27017.

Attachments


Status changed to Awaiting User Response railway[bot] 5 months ago


fedealconadaPRO

5 months ago

On staging environment I have the same (port 5432) and it works fine... It's also the one that you can see by default on the UI when adding the TPC Proxy port...


Status changed to Awaiting Railway Response railway[bot] 5 months ago


5 months ago

That is a placeholder -

https://www.w3schools.com/tags/att_input_placeholder.asp

Please use the correct port.


Status changed to Awaiting User Response railway[bot] 5 months ago


fedealconadaPRO

5 months ago

Yes, I know what a placeholder is, I'm just saying it because it is misleading... you could have a placeholder with the correct port. Still, you have not answered my question nor solved my issue. I mentioned that on the staging environment I'm using port 5432 without issues, so how come I can't use it on production?


Status changed to Awaiting Railway Response railway[bot] 5 months ago


5 months ago

> you could have a placeholder with the correct port.

Since the TCP Proxy is a global primitive available for all services, the proxy doesn't know what is and isn't the correct port.

I do not know why it works, but I do know that it is not the port mongo listens on, please use the correct port for mongo and report back!


Status changed to Awaiting User Response railway[bot] 5 months ago