# MongoServerError: Transaction numbers are only allowed on a replica set member or mongos

**Code:** `Transaction numbers are only allowed on a replica set member or mongos` · **Category:** MongoDB · **Seen on:** MongoDB, Node.js

You started a transaction (or used retryWrites) on a standalone MongoDB server, which doesn't support them.

## 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?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/mongodb/transaction-numbers-are-only-allowed-on-a-replica-set)
