How could I connect to a mongodb database from railway?

im searched online but its been a bit confusing based on what info railway gives me
47 Replies
Percy
Percy2mo ago
Project ID: 4c05d88f-1ba0-4c53-b525-f736d53d0a33
loyahdev
loyahdev2mo ago
4c05d88f-1ba0-4c53-b525-f736d53d0a33
Brody
Brody2mo ago
may i ask whats confusing? deploy mongo into your project, then setup reference variables on your desired service -
MONGO_URL=${{MongoDB.MONGO_URL}}
MONGO_URL=${{MongoDB.MONGO_URL}}
and then use the MONGO_URL environment variable in your code with whatever mongo client you like
loyahdev
loyahdev2mo ago
im trying to connect through mongodb vs code but its just saying: Unable to load connection: MongoServerSelectionError: connection <monitor> to 35.212.138.205:43765 closed
Brody
Brody2mo ago
you are trying to connect to mongodb on railway locally?
loyahdev
loyahdev2mo ago
yes im trying to connect to the railway mongodb server locally through vs code
Brody
Brody2mo ago
what does vscode have to do with this?
loyahdev
loyahdev2mo ago
im not specifically saying vs code it does the same error through terminal im jut trying to remove some entries in the database but i need to connect to it
Brody
Brody2mo ago
what database client are you trying to use
loyahdev
loyahdev2mo ago
im not using any im jusgt using vscode extensions that allow for database stuff
Brody
Brody2mo ago
try with dbgate
loyahdev
loyahdev2mo ago
on it
loyahdev
loyahdev2mo ago
this didnt seem to work
No description
Brody
Brody2mo ago
i dont see an error?
loyahdev
loyahdev2mo ago
im trying to get one here
Brody
Brody2mo ago
click test
loyahdev
loyahdev2mo ago
same error that we got before
No description
Brody
Brody2mo ago
what is the deployment status of the mongodb
loyahdev
loyahdev2mo ago
its active
No description
Brody
Brody2mo ago
can you give me the host and port for the database?
loyahdev
loyahdev2mo ago
roundhouse.proxy.rlwy.net 43765
Brody
Brody2mo ago
https://utilities.up.railway.app/port-check?host=roundhouse.proxy.rlwy.net&port=43765 are you on school, work, public internet? you could be behind a firewall that blocks non common ports, 43765 is not a common port
loyahdev
loyahdev2mo ago
nope im at home and arent using a firewall is there a way i could test jsut connecting to the port regularly?
Brody
Brody2mo ago
what os are you using?
loyahdev
loyahdev2mo ago
macos 14.5
Brody
Brody2mo ago
does that come with the nc command?
loyahdev
loyahdev2mo ago
yup
Brody
Brody2mo ago
nc -zv roundhouse.proxy.rlwy.net 43765
loyahdev
loyahdev2mo ago
jaxonhensch@MacBook-Pro-9 ~ % nc -zv roundhouse.proxy.rlwy.net 43765
Connection to roundhouse.proxy.rlwy.net port 43765 [tcp/*] succeeded!
jaxonhensch@MacBook-Pro-9 ~ % nc -zv roundhouse.proxy.rlwy.net 43765
Connection to roundhouse.proxy.rlwy.net port 43765 [tcp/*] succeeded!
it works
Brody
Brody2mo ago
interesting try redeploying the database
loyahdev
loyahdev2mo ago
got it i get the same connection error
Brody
Brody2mo ago
can you connect to this with dbgate? - mongodb://mongo:mCLJxOdpiWxZHTXLNdateBAWzlDcLzWk@monorail.proxy.rlwy.net:50629
loyahdev
loyahdev2mo ago
yup i can it works
Brody
Brody2mo ago
screenshot of the tcp proxy for mongo please
loyahdev
loyahdev2mo ago
this?
No description
Brody
Brody2mo ago
yeah, 27021 is wrong, remove the proxy and add it back with 27017, this will then change the url service variable so be sure to copy it again and try with dbgate
loyahdev
loyahdev2mo ago
do i have to redeploy?
loyahdev
loyahdev2mo ago
because i fixed it
No description
Brody
Brody2mo ago
dont think so copy your new url and try with dbgate
loyahdev
loyahdev2mo ago
same error
mongodb://mongo:(pass)@roundhouse.proxy.rlwy.net:37449
mongodb://mongo:(pass)@roundhouse.proxy.rlwy.net:37449
Connect failed: connection <monitor> to 35.212.138.205:37449 closed
Connect failed: connection <monitor> to 35.212.138.205:37449 closed
Brody
Brody2mo ago
send me your mongo deloy logs please https://bookmarklets.up.railway.app/log-downloader/
Brody
Brody2mo ago
have you tried to redeploy?
loyahdev
loyahdev2mo ago
not yet i will now it worked! connecting is perfect
Brody
Brody2mo ago
odd, but good!
loyahdev
loyahdev2mo ago
well thank you so much
Brody
Brody2mo ago
no problem! next time you open a help thread for an error, please include that error in the post