Prisma - The provided database string is invalid. MongoDB connection string error
Asked Answered
S

5

7

I'm being told I have an invalid connection string for my MongoDB data provider.

Specifically, I'm getting this: The provided database string is invalid. MongoDB connection string error: Missing delimiting slash between hosts and options in database URL.

My problem, however, is that my connection string does have a delimiting slash: it's this: mongodb://<user>:<pass>@cluster0.<server>.mongodb.net/?retryWrites=true&w=majority

What's going on? Is there anything I'm missing?

Shoveler answered 10/10, 2022 at 11:7 Comment(0)
I
19

It's missing database name after host: mongodb://<user>:<pass>@cluster0.<server>.mongodb.net/<mydb>?retryWrites=true&w=majority

Illegality answered 10/10, 2022 at 13:34 Comment(0)
B
11

For someone who tried to connect mongodb in prisma, maybe you choose wrong connect , try to use type connect using VSCode

mongodb+srv://<admin>:<password>@cluster0.8hjts4c.mongodb.net/test 

it must have /test

Basilio answered 5/4, 2023 at 7:53 Comment(1)
Thanks this worked! Life saver comment :3Loser
H
1

Make sure your password do not contain any special character in your mongodb url string.

 DATABASE_URL="mongodb+srv://<user>:<pass>@<cluster_name>/<colection_name>? 
 retryWrites=true&w=majority"

i.e

 DATABASE_URL="mongodb+srv://sammy:devland@<cluster_name>/<colection_name>? 
 retryWrites=true&w=majority"
Horsehair answered 12/7, 2024 at 13:32 Comment(0)
S
0

If you are using mongodb then just write database name as the path (replace <name> etc.)

mongodb://<user>:<pass>@cluster0.<server>.mongodb.net/<name>?retryWrites=true&w=majority
Suck answered 14/3, 2023 at 10:19 Comment(0)
U
0

I was getting the same error resolved by checking the connection URI String by following

 DATABASE_URL="mongodb+srv://<user>:<pass>@<cluster_name>/<colection_name>? 
 retryWrites=true&w=majority"

Here collection name is important

Unattached answered 10/6, 2024 at 8:53 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.