can i connect to mongoDB on local
my project was working on VPS server so im using local settings and now after i change it to railway i got alot of errors there is a way to connect local ?
30 Replies
Project ID:
N/A
It appears that it is possible to connect to MongoDB on local, but it may be blocked by your local network or IP. It is recommended to check the credentials and variables tab to ensure that the connection is set up correctly.
β οΈ experimental feature
yep, use the environment variables railway provides (https://docs.railway.app/databases/mongodb#connect) in your code, run railway shell to get a shell that has all your projects variables set for you, then you can start your app the same way you normally would
can you join A voice chat ?
no
on my version i use it like that
const dbUrl =
mongodb://${Config.get("databaseHost")}:${Config.get("databasePort")}/${Config.get("databaseName")}
;
but now
const dbUrl = mongodb://${Config.get("databaseUser")}:${Config.get("databasePass")}@${Config.get("databaseHost")}:${Config.get("databasePort")}
;
so every time i put ${Config.get("databaseName")} i got an errorjavascript?
yes
for JavaScript you use process.env.ENV_VARIABLE so for example to get the host for the railway mongodb you would use process.env.MONGOHOST
that is not my point
thanks for you
but im asking how i can connect to databasename direct
im saying dont use that Config.get function, just get the environment variable
yes, and i gave you the answer
i know im asking a lot sorry for that
thank you
you are over complicating the connection process
so i dont need to use database name while im connect
i got that point and i will use env
thanks for your help
try connection with the injected enviroment variables and report back if that works π always good to follow up
its connected to
test
DatabaseOkay connection works, that's great
yeah
but still im on the same point π’
how i can connect to my database
Where is "your" database hosted?
on railway
That screenshot of the mongodb Uri would connect to the database in the project
by default its connect to
test
DB i need to make it to APIs
when im trying like that i got error
I'm not familiar with mongodb, it sounds like a cop out answer but I'm sure this an easily googleable question, "how to set default database mongodb nodejs"
ok thank you
Remember to come back with the answer once you found it π
sure
Hello @Brody
i solve the problem
that is DB name on newer version of mongos should be throw options not directly
Awesome, this might help someone in the future π