question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Prisma+MongoDB+Docker Prisma needs to perform transactions, which requires your MongoDB server to be run as a replica set

See original GitHub issue

Bug description

#prismaClient.ts

import { PrismaClient as PrismaClientMongoDb } from '../mongodb/generated/mongodb';
const mongodb = new PrismaClientMongoDb({
  log: ['query', 'info'],
});

export { postgres, mongodb };

Here schema-mongodb.prisma

generator clientMongoDb {
  provider = "prisma-client-js"
  output   = "./generated/mongodb"
}

datasource db {
  provider = "mongodb"
  url      = env("DATABASE_URL_MONGODB")
}

model PageAccessCounter {
  id         String   @id @default(auto()) @map("_id") @db.ObjectId
  created_at DateTime @default(now())
  updated_at DateTime @updatedAt

  @@map("page_access_counters")
}

.env

DATABASE_URL_MONGODB="mongodb://root:tests123@127.0.0.1:27017/shoofertaecommerce?authSource=admin&retryWrites=true&w=majority&directConnection=true&ssl=false&&readPreference=primary&replicaSet=prefer"

follow error code: ‘P2031’, await this.prismaRepository.pageAccessCounter.create(Prisma needs to perform transactions, which requires your MongoDB server to be run as a replica set.)

How to reproduce

Expected behavior

No response

Prisma information

database credentials Prisma schema tests123

Environment & setup

  • OS: Ubuntu 20.04.4 LTS
  • Docker: Docker version 20.10.12, build 20.10.12-0ubuntu2~20.04.1
  • Database: MONGODB
  • Node.js version: v16.15.0

Prisma Version

  clientVersion: '3.13.0',
  meta: {}

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
garrensmithcommented, May 23, 2022

@Djamilson could you give me a bit more context. Did that setup fix the issue or did you get another issue?

0reactions
Djamilsoncommented, May 22, 2022

docker-compose.yml

version: ‘3.7’ services:

mongodb_container:
image: prismagraphql/mongo-single-replica:4.4.3-bionic restart: always

environment:
  MONGO_INITDB_ROOT_USERNAME: user
  MONGO_INITDB_ROOT_PASSWORD: password

ports:
  - 27017:27017

volumes:
  - mongo:/var/lib/mongo

volumes: mongo: `

Read more comments on GitHub >

github_iconTop Results From Across the Web

Make the MongoDB Replica Set Requirement Optional in ...
Prisma needs to perform transactions, which requires your MongoDB server to be run as a replica set. Honestly would be really nice if...
Read more >
Using Prisma with MongoDB
When using transactions, MongoDB requires replication of your data set to be enabled. To do this, you will need to configure a replica...
Read more >
Prisma + MongoDB -> Replica set - Stack Overflow
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 ......
Read more >
Lightning Fast Guide on Prisma MongoDB Connection using ...
However, supporting transactions means that we need to have a replica set. There are a couple of ways to solve this. First option...
Read more >
How to deploy a MongoDB Replica Set using Docker
I have written a new article about how to deploy a mongodb cluster using a DevOps fashion Style, in this article i am...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found