How to connect to mongoDb locally #9994
|
Hey all, So I've been able to connect to a MongoDB cluster with Prisma but not locally. I have a And this is the error message I get: The provided database string is invalid. Invalid MongoDB connection string in database URL. Please refer to the documentation in https://www.prisma.io/docs/reference/database-reference/connection-urls for constructing a correct connection string. In some cases, certain characters must be escaped. Please check the string for any illegal characters. I am using Prisma with Express and GraphQL but I don't think that should make a difference. With the same values above I am able to connect to MongoDB Compass fine but not with Prisma 🤔 Any ideas? |
Replies: 17 comments 34 replies
|
Hey @RichardBray 👋! Are you trying to connect to MongoDB Atlas while running locally or are you running Mongo locally? If you are running Mongo locally, try removing Let me know! |
|
I figured the issue out, I needed to add this to In the mongo shell, I need to change the table to "admin" before I can authenticate. Maybe Compass adds this for you automatically. For anyone interested the working env variable looks like this: Thanks for all your help @austincrim |
|
you guys should put a proper example of how can I connect to mongo URI based on this my URL will become |
|
any updates on it ? I'm facing the same issue @tkssharma |
|
I am facing the same issue. I don't want to do it on the cloud. I absolutely have to do it locally in a docker container... any tips? EDIT: Finally, I used this setup : https://github.com/prisma/prisma-examples/blob/latest/databases/mongodb/docker-compose.yml and this env variable |
|
This information should probably be added in the docs. |
|
For future reference, I wrote this article for this issue. |
|
Thanks 👍🏻
…On Wed, Oct 26, 2022, 7:22 PM mohammadsaadshafiq ***@***.***> wrote:
For future reference, I wrote this article for this issue.
***@***.***/connect-prisma-with-mongo-db-image-358ddcc300ee
—
Reply to this email directly, view it on GitHub
<#9994 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ARGAN6QGVHM52HUKX2Y4UXDWFEZSRANCNFSM5G4R7FTQ>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
|
in my case this code solved. do remove +rsv if you want to connect to your local mongodb |
|
Maybe it's because of the mongo I'm running on a container, but adding this: |
|
I had a running mongo service on my Mac. So I had to shut it down first - then it worked. How to shut it down: |
|
How do I set username and password on local machine? |
|
I was facing the same issue trying to dockerize a full stack app which was originally developed using React, Tailwind, Next, Prisma, Mongo Atlas, NextAuth. |
|
The issue that persists is that mongodb should be a replica set and the url should have I have created an npm package to fix this issue and simplify the process: https://github.com/haneenmahd/dmp |
|
Adding
also, here is my dockerfile config |
|
If you are looking down this far then that means you've exhausted all the other solutions. For me the way I got it working is that I had my connection string set in .env but I have another connection string in a prisma.services file and the schema.prisma was actually reading the url from there. I ended up changing the url to the right one and it ended up working, Hopefully this helps P.S if it still doesnt work, try adding ?authSource=admin to the end of the connection string. That should do the trick. |
|
Latest update https://www.mongodb.com/docs/atlas/cli/current/atlas-cli-deploy-docker/ |
I figured the issue out, I needed to add this to
?authSource=adminIn the mongo shell, I need to change the table to "admin" before I can authenticate. Maybe Compass adds this for you automatically.
For anyone interested the working env variable looks like this:
Thanks for all your help @austincrim