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.
3
Answers
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].0 generate" for this old version.
Local Instance with docker
An easy to use docker image is available that creates a single instance replica
docker pull prismagraphql/mongo-single-replica:5.0.3
You must provide authSource=admin option otherwise authentication will fail
MongoDB Atlas
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