# MongoServerError: RollbackDetected: rollback occurred on replica set member rs1:27017

- **ID:** `mongodb/rollback-detected-on-replica-set`
- **Domain:** mongodb
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

A secondary node in a replica set experienced a rollback because it applied writes that were later overwritten by the primary.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| mongodb-5.0 | active | — | — |
| mongodb-6.0 | active | — | — |
| mongodb-7.0 | active | — | — |

## Workarounds

1. **Check the rollback data in the rollback/ directory on the affected node and manually restore any necessary documents using mongorestore.** (80% success)
   ```
   Check the rollback data in the rollback/ directory on the affected node and manually restore any necessary documents using mongorestore.
   ```
2. **Ensure all secondary nodes have caught up with the primary by monitoring replication lag and increasing oplog size if needed.** (85% success)
   ```
   Ensure all secondary nodes have caught up with the primary by monitoring replication lag and increasing oplog size if needed.
   ```
3. **Set writeConcern to majority to reduce the chance of rollbacks by ensuring writes are acknowledged by a majority of nodes.** (75% success)
   ```
   Set writeConcern to majority to reduce the chance of rollbacks by ensuring writes are acknowledged by a majority of nodes.
   ```

## Dead Ends

- **** — Ignoring the rollback and continuing operations can cause data inconsistency between nodes. (50% fail)
- **** — Manually forcing the secondary to become primary without resolving the rollback can cause data loss. (50% fail)
- **** — Decreasing the oplog size to save disk space increases the likelihood of future rollbacks. (50% fail)
