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:Jump to solution
Prisma requires MongoDB to be run as replica set which MongoBD on railway doesn't support yet.
45 Replies
Project ID:
b1b6bd17-9af8-4f3b-81e0-ee45984024d7
b1b6bd17-9af8-4f3b-81e0-ee45984024d7
prisma can work with mongodb?
Yes why not
fancy
1. are you using environment variables
2. are you using
railway run
?I know migrate isnt supported, is db push? https://www.prisma.io/docs/concepts/database-connectors/mongodb#no-support-for-prisma-migrate
I tried with MongoDB Atlas, it's all working fine, but this is first time try with railway
in that case its very likely an env issue as @Brody mentioned
I simply copy the connection url to "DATABASE_URL":
datasource db {
provider = "mongodb"
url = env("DATABASE_URL")
}
just to be clear, are you now trying this with a railway provided databases?
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
Yes the database url is my railway mongodb connection url
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 anymorenow please reset your password for that ...
This is the error.
next time please dont post the whole thing
yes what Luna said
my bad but it was a deleted database url.
show me a screenshot of your project that contains your service
sorry I dont get it
a screenshot
of your browser window
with the project open
the railway project
where is the service
that's just a database
I just use the database all code are running locally.
This is also what I did with my previous project but with postgresql
ugh I hate .env files
do you have the railway cli installed
nope
ugh
fine use the .env file
what does the .env look like? similar to this?
this db is deleted so dont worry.
Yes it's like this
does prisma load variables from a .env file by default
yes from this
yes
There's gotta be a copy+paste error somewhere in that url that's the only reason that should throw that error.
The database url is copied directly from railway
0 chances for typo
🤔
is the database string quoted in your .env file?
tried both with or without quotes, same result
this doesn't seem to be a railway issue, so ima go to bed 🙂
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.
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.
yes, will try. Thanks.
Solution
Prisma requires MongoDB to be run as replica set which MongoBD on railway doesn't support yet.
I ran into the same problem.
As I understand it, Prisma w. Mongo (still) isn't supported by Railway - correct?
that's what the marked answer says