Transaction numbers are only allowed on a replica set member or mongos MongoDB Origin: Data OSI layer 7 · Application Last updated 5 Nov 2026

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.

Exact message you may see 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
Seen on: MongoDB Node.js

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=true on a standalone server
  • Local dev without replica set
  • Docker mongo without --replSet
  • Prisma/Mongoose features requiring transactions

⚡ Quick fix

  1. Run a single-node replica set: mongod --replSet rs0 then rs.initiate()
  2. Add ?retryWrites=false for standalone
  3. Use Atlas or a managed cluster

Detailed fix by platform

mongosh

  1. rs.initiate({ _id: "rs0", members: [{ _id: 0, host: "localhost:27017" }] })

How to diagnose

  1. Topology — Standalone or replica set?
  2. Feature — Transaction or retryWrites?
  3. 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:

Where this error sits

Origin: Data. Errors that are often confused with or caused by this one (click to open):

AlreadyInitialized: already initialized — MongoServerError: already initialized (rs.initiate on a configured replica set) (MongoDB)AlreadyInitialized: a…Could not find host matching read preference — MongoServerSelectionError: Could not find host matching read preference { mode: "secondary" } for set rs0 (MongoDB)Could not find host m…MongoServerSelectionError — MongooseServerSelectionError: connect ECONNREFUSED 127.0.0.1:27017 (Node.js)MongoServerSelectionE…No primary found in replica set / ReplicaSetNoPrimary — MongoServerSelectionError: Server selection timed out after 30000 ms — topology type ReplicaSetNoPrimary (MongoDB)No primary found in r…NoSuchTransaction: Transaction was aborted or expired — MongoServerError: Transaction 1 has been aborted / NoSuchTransaction: transaction has expired (transactionLifetimeLimitSeconds) (MongoDB)NoSuchTransaction: Tr…NotWritablePrimary: not primary and secondaryOk=false — MongoServerError: not primary and secondaryOk=false / NotWritablePrimary: not master (MongoDB)NotWritablePrimary: n…rs.initiate failed: member not reachable / no host described in new configuration — MongoDB: replSetInitiate quorum check failed: Could not connect to mongo2:27017 / No host described in new configuration 1 for replica set rs0 maps to this node (MongoDB)rs.initiate failed: m…WriteConflict: Write conflict during plan execution — MongoServerError: WriteConflict error: this operation conflicted with another operation. Please retry your operation or multi-document transaction (MongoDB)WriteConflict: Write …Transacti…

Explore the map of this error Full error map →

🧠 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.