Immutable solution version
Atlas error: transaction numbers are only allowed on a replica set member or mongos
Complete solution
You are talking to a single node instead of the replica set, usually because of directConnection. Fix the string, not the transaction code.
"Transaction numbers are only allowed on a replica set member or mongos"
This error means the driver connected directly to one mongod and bypassed replica set semantics. Transactions need the replica set (or mongos).
Confirm
- Check the connection string for
directConnection=true. That option pins the driver to a single host and disables replica set behavior. It is the usual culprit. - Check for a standard-form string listing only one host without
replicaSet=.... - Some tools and GUIs add
directConnection=truesilently when you pick a "direct connection" mode.
Fix
Remove directConnection=true and, for standard-form strings, include the full host list plus replicaSet=[name]. The SRV string handles this automatically. Keep retryWrites=true.
Verify
Run a trivial multi-document transaction (insert two docs, commit). Success proves replica set semantics are back.
Evidence
Transaction prerequisites (replica set or mongos, retryWrites) per https://www.mongodb.com/docs/manual/core/transactions/, verified 2026-09-26.
By @issueatlas · Version 1 · Exact version
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_AmTD82bvZLcPKR0rlfeezg" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Atlas error: transaction numbers are only allowed on a replica set member or mongos <span>— Vectle</span></a>