Error Invalid "prisma.user.create()". Prisma needs to perform transactions, which requires your MongoDB server to be run as a replica set.
I used Nx (nx.dev) with MongoDB/Express with Prisma.
Error Invalid "prisma.user.create()". Prisma needs to perform transactions, which requires your MongoDB server to be run as a replica set.
I used Nx (nx.dev) with MongoDB/Express with Prisma.
An easy to use docker image is available that creates a single instance replica
docker pull prismagraphql/mongo-single-replica:5.0.3
docker run --name mongo \
-p 27017:27017 \
-e MONGO_INITDB_ROOT_USERNAME="monty" \
-e MONGO_INITDB_ROOT_PASSWORD="pass" \
-d prismagraphql/mongo-single-replica:5.0.3
DATABASE_URL="mongodb://monty:pass@localhost:27017/db_name?authSource=admin&directConnection=true"
You must provide authSource=admin option otherwise authentication will fail
DATABASE_URL="mongodb+srv://username:password@cluster_name.random_string.net/db_name?retryWrites=true&w=majority"
Note that the official documentaion currently follows the previous format used for the local instance but here it does not include the port number and has the +srv suffix, without which I ran into some problems.
If you want use the format used in the documentation then you must provide the option ssl=true and for the hostname you have to use the primary cluster which looks like random_string.mongodb.net:27017, which you can find in the overview tab after clicking in your cluster name
Apparently, after long hours of facing continuous issues in connecting Prisma and MongoDB(local), we have 3 ways of fixing this. You have to use either Docker or MongoDB Atlas.
Docker - Docker
MongoDB Atlas - MongoDB Replica
Ps. Your MongoDB URL env should be looking like this -> mongodb://localhost:27017/<your-db-name>?retryWrites=true&w=majority
.
I decided to finally choose the option 3. Jumping from MongoDB to PostgreSQL which don't have any replica issues, but no noSQL :)
You can use "prisma": "2.26.0" and "@prisma/client": "2.26.0" instead of your current version. They don`t need a replica set. Also you have to use @default(dbgenerated()) instead of @default(auto()) both with "npx [email protected] generate" for this old version.
© 2022 - 2024 — McMap. All rights reserved.