R
Railway•2y ago
yiyuan9

mongodb connection url error while using prisma

Hi, trying to connect mongodb to my project while using prisma as orm. When i do "npx prisma db push", it shows error regarding the connection url. Any fixes? Or I will have to use other tools when working with prisma. Thanks in advance.
Solution:
Prisma requires MongoDB to be run as replica set which MongoBD on railway doesn't support yet.
Jump to solution
45 Replies
Percy
Percy•2y ago
Project ID: b1b6bd17-9af8-4f3b-81e0-ee45984024d7
yiyuan9
yiyuan9OP•2y ago
b1b6bd17-9af8-4f3b-81e0-ee45984024d7
Brody
Brody•2y ago
prisma can work with mongodb?
yiyuan9
yiyuan9OP•2y ago
Yes why not
Brody
Brody•2y ago
fancy 1. are you using environment variables 2. are you using railway run?
yiyuan9
yiyuan9OP•2y ago
I tried with MongoDB Atlas, it's all working fine, but this is first time try with railway
luna
luna•2y ago
in that case its very likely an env issue as @Brody mentioned
yiyuan9
yiyuan9OP•2y ago
I simply copy the connection url to "DATABASE_URL": datasource db { provider = "mongodb" url = env("DATABASE_URL") }
Brody
Brody•2y ago
just to be clear, are you now trying this with a railway provided databases?
luna
luna•2y ago
locally or when you deployed? When deploying you shouldnt need to provide the DATABASE_URL as railway will add that for you if you're using a railway provided mongodb instance. locally you should be using a .env file for the DATABASE_URL
yiyuan9
yiyuan9OP•2y ago
Yes the database url is my railway mongodb connection url
Brody
Brody•2y ago
show me a screenshot of your service variables please little correction, locally you use railway run when developing apps to run on railway. you don't need a local .env file anymore
luna
luna•2y ago
now please reset your password for that ...
yiyuan9
yiyuan9OP•2y ago
This is the error.
luna
luna•2y ago
next time please dont post the whole thing
Brody
Brody•2y ago
yes what Luna said
yiyuan9
yiyuan9OP•2y ago
my bad but it was a deleted database url.
Brody
Brody•2y ago
show me a screenshot of your project that contains your service
yiyuan9
yiyuan9OP•2y ago
sorry I dont get it
Brody
Brody•2y ago
a screenshot of your browser window with the project open the railway project
yiyuan9
yiyuan9OP•2y ago
Brody
Brody•2y ago
where is the service that's just a database
yiyuan9
yiyuan9OP•2y ago
I just use the database all code are running locally. This is also what I did with my previous project but with postgresql
Brody
Brody•2y ago
ugh I hate .env files do you have the railway cli installed
yiyuan9
yiyuan9OP•2y ago
nope
Brody
Brody•2y ago
ugh fine use the .env file
luna
luna•2y ago
what does the .env look like? similar to this? this db is deleted so dont worry.
DATABASE_URL="mongodb://mongo:[email protected]:7044"
DATABASE_URL="mongodb://mongo:[email protected]:7044"
yiyuan9
yiyuan9OP•2y ago
Yes it's like this
Brody
Brody•2y ago
does prisma load variables from a .env file by default
yiyuan9
yiyuan9OP•2y ago
yes from this
luna
luna•2y ago
yes There's gotta be a copy+paste error somewhere in that url that's the only reason that should throw that error.
yiyuan9
yiyuan9OP•2y ago
The database url is copied directly from railway 0 chances for typo
luna
luna•2y ago
🤔
Brody
Brody•2y ago
is the database string quoted in your .env file?
yiyuan9
yiyuan9OP•2y ago
tried both with or without quotes, same result
Brody
Brody•2y ago
this doesn't seem to be a railway issue, so ima go to bed 🙂
yiyuan9
yiyuan9OP•2y ago
Thanks for the help tho, I think it might be the way prisma reads mongodb database url, the @ sign in the url could be the cause.
luna
luna•2y ago
its 100% something with the url, the @ is fine as it's expected to be there. maybe try the same url you're getting from railway in a mongodb viewing app and see if you get the same error.
yiyuan9
yiyuan9OP•2y ago
yes, will try. Thanks.
Solution
yiyuan9
yiyuan9•2y ago
Prisma requires MongoDB to be run as replica set which MongoBD on railway doesn't support yet.
luna
luna•2y ago
Zvezke
Zvezke•2y ago
I ran into the same problem. As I understand it, Prisma w. Mongo (still) isn't supported by Railway - correct?
Brody
Brody•2y ago
that's what the marked answer says
Want results from more Discord servers?
Add your server