MongoServerError: Transaction numbers are only allowed on a replica set member or mongos
You started a transaction (or used retryWrites) on a standalone MongoDB server, which doesn't support them.
Transaction numbers are only allowed on a replica set member or mongosMongoServerError: Transaction numbers are only allowed on a replica set memberMongoError: This MongoDB deployment does not support retryable writes. Please add retryWrites=false to your connection stringPrisma needs MongoDB replica set Transactions Meaning
Multi-document transactions require a replica set. For local development, run a single-node replica set: start mongod --replSet rs0 and run rs.initiate(), or use the Atlas free tier / Docker image with --replSet. Alternatively disable retryWrites=false in the URI for standalone.
Common causes
- Standalone mongod used with transactions
retryWrites=trueon a standalone server- Local dev without replica set
- Docker mongo without --replSet
- Prisma/Mongoose features requiring transactions
⚡ Quick fix
- Run a single-node replica set:
mongod --replSet rs0thenrs.initiate() - Add
?retryWrites=falsefor standalone - Use Atlas or a managed cluster
Detailed fix by platform
mongosh
rs.initiate({ _id: "rs0", members: [{ _id: 0, host: "localhost:27017" }] })
How to diagnose
- Topology — Standalone or replica set?
- Feature — Transaction or retryWrites?
- Dev — Local replica set?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
- AlreadyInitialized: already initialized MongoServerError: already initialized (rs.initiate on a configured replica set)
- Could not find host matching read preference MongoServerSelectionError: Could not find host matching read preference { mode: "secondary" } for set rs0
- MongoServerSelectionError MongooseServerSelectionError: connect ECONNREFUSED 127.0.0.1:27017
Most viewed in MongoDB
- Document failed validation MongoDB: MongoServerError: Document failed validation (code 121)
- MongoParseError MongoDB: MongoParseError: Invalid scheme, expected connection string to start with "mongodb://" or "mongodb+srv://"
- bad auth : Authentication failed MongoDB: MongoServerError: bad auth : Authentication failed (code 8000 / 18)
Other ways to find it
Where this error sits
Origin: Data. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 5 Nov 2026