R
Railwayβ€’2y ago
BAG | AZIZ

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
Percy
Percyβ€’2y ago
Project ID: N/A
Percy
Percyβ€’2y ago
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
Brody
Brodyβ€’2y ago
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
BAG | AZIZ
BAG | AZIZOPβ€’2y ago
can you join A voice chat ?
Brody
Brodyβ€’2y ago
no
BAG | AZIZ
BAG | AZIZOPβ€’2y ago
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 error
Brody
Brodyβ€’2y ago
javascript?
BAG | AZIZ
BAG | AZIZOPβ€’2y ago
yes
Brody
Brodyβ€’2y ago
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
BAG | AZIZ
BAG | AZIZOPβ€’2y ago
that is not my point thanks for you but im asking how i can connect to databasename direct
Brody
Brodyβ€’2y ago
im saying dont use that Config.get function, just get the environment variable yes, and i gave you the answer
BAG | AZIZ
BAG | AZIZOPβ€’2y ago
i know im asking a lot sorry for that thank you
Brody
Brodyβ€’2y ago
you are over complicating the connection process
BAG | AZIZ
BAG | AZIZOPβ€’2y ago
so i dont need to use database name while im connect i got that point and i will use env thanks for your help
Brody
Brodyβ€’2y ago
try connection with the injected enviroment variables and report back if that works πŸ™‚ always good to follow up
BAG | AZIZ
BAG | AZIZOPβ€’2y ago
BAG | AZIZ
BAG | AZIZOPβ€’2y ago
its connected to test Database
Brody
Brodyβ€’2y ago
Okay connection works, that's great
BAG | AZIZ
BAG | AZIZOPβ€’2y ago
yeah but still im on the same point 😒
BAG | AZIZ
BAG | AZIZOPβ€’2y ago
how i can connect to my database
Brody
Brodyβ€’2y ago
Where is "your" database hosted?
BAG | AZIZ
BAG | AZIZOPβ€’2y ago
on railway
Brody
Brodyβ€’2y ago
That screenshot of the mongodb Uri would connect to the database in the project
BAG | AZIZ
BAG | AZIZOPβ€’2y ago
by default its connect to test DB i need to make it to APIs
BAG | AZIZ
BAG | AZIZOPβ€’2y ago
when im trying like that i got error
Brody
Brodyβ€’2y ago
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"
BAG | AZIZ
BAG | AZIZOPβ€’2y ago
ok thank you
Brody
Brodyβ€’2y ago
Remember to come back with the answer once you found it πŸ™‚
BAG | AZIZ
BAG | AZIZOPβ€’2y ago
sure Hello @Brody i solve the problem that is DB name on newer version of mongos should be throw options not directly
Brody
Brodyβ€’2y ago
Awesome, this might help someone in the future πŸ™‚
Want results from more Discord servers?
Add your server