mongodb/node-mongodb-native · error · MongoServerError
This MongoDB deployment does not support retryable writes. P
Error message
This MongoDB deployment does not support retryable writes. Please add retryWrites=false to your connection string.
What it means
In executeOperationWithRetries (src/operations/execute_operation.ts:289), when a write operation fails with code IllegalOperation (the MMAPv1 retry-writes error), the driver throws a MongoServerError with a fixed message instructing the user to disable retryWrites. MMAPv1 and certain pre-4.0 standalone deployments cannot support retryable writes, and retryWrites defaults to true.
Source
Thrown at src/operations/execute_operation.ts:289
} catch (operationError) {
// Should never happen but if it does - propagate the error.
if (!(operationError instanceof MongoError)) throw operationError;
// Preserve the original error once a write has been performed.
// Only update to the latest error if no writes were performed.
if (error == null) {
error = operationError;
} else {
if (!operationError.hasErrorLabel(MongoErrorLabel.NoWritesPerformed)) {
error = operationError;
}
}
// Reset timeouts
timeoutContext.clear();
if (hasWriteAspect && operationError.code === MMAPv1_RETRY_WRITES_ERROR_CODE) {
throw new MongoServerError({
message: MMAPv1_RETRY_WRITES_ERROR_MESSAGE,
errmsg: MMAPv1_RETRY_WRITES_ERROR_MESSAGE,
originalError: operationError
});
}
if (!canRetry(operation, operationError)) {
throw error;
}
if (operationError.hasErrorLabel(MongoErrorLabel.SystemOverloadedError)) {
const maxOverloadAttempts = topology.s.options.maxAdaptiveRetries + 1;
maxAttempts = Math.min(maxOverloadAttempts, operation.maxAttempts ?? maxOverloadAttempts);
}
if (attempt + 1 >= maxAttempts) {
throw error;
}View on GitHub (pinned to 3366c21a63)
Solutions
- Add retryWrites=false to the connection string as the message instructs.
- Upgrade the storage engine from MMAPv1 to WiredTiger (MongoDB 4.0+ default).
- For a standalone server, switch to a replica set to gain retryable-writes support.
- Verify the deployment version/topology with db.serverStatus().storageEngine.
Example fix
// before
const uri = 'mongodb://localhost:27017'; // MMAPv1 standalone
const client = new MongoClient(uri);
await client.db().collection('x').insertOne({ a: 1 }); // throws
// after
const uri = 'mongodb://localhost:27017/?retryWrites=false';
const client = new MongoClient(uri);
await client.db().collection('x').insertOne({ a: 1 }); Defensive patterns
Strategy: validation
Validate before calling
// Detect incompatible deployment before writes
const admin = client.db().admin();
const status = await admin.command({ serverStatus: 1 });
const engine = status.storageEngine?.name;
if (engine === 'mmapv1') {
// disable retryWrites in the URI: retryWrites=false
} Try / catch
try {
await collection.insertOne(doc);
} catch (err) {
if (err instanceof MongoServerError && /retryWrites=false/.test(err.message)) {
// reconnect with retryWrites=false or upgrade the deployment
} else throw err;
} Prevention
- Add retryWrites=false to the connection string when targeting MMAPv1 or standalone deployments.
- Prefer WiredTiger and replica-set/sharded topologies for retryable-writes support.
- Verify storage engine with db.serverStatus().storageEngine.name.
When it happens
Trigger: Running a write operation (insert/update/delete/findOneAndUpdate/etc.) with the default retryWrites=true against a deployment whose storage engine or topology does not support retryable writes — most notably MMAPv1 or a standalone server.
Common situations: Legacy MongoDB 3.x standalone, a replica set with MMAPv1 storage engine, or a misconfigured test instance. The default retryWrites=true in modern drivers triggers this on incompatible deployments.
Related errors
- Current topology does not support sessions
- AuthContext must provide credentials.
- Driver attempted to initialize in load balancing mode, but t
- Option "srvHost" must not be empty
- No addresses found at host
AI-assisted analysis of mongodb/node-mongodb-native@3366c21a63 (2026-08-04).
Data as JSON: /data/errors/cf2419c1d6e7ed9d.json.
Report an issue: GitHub.