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

  1. Add retryWrites=false to the connection string as the message instructs.
  2. Upgrade the storage engine from MMAPv1 to WiredTiger (MongoDB 4.0+ default).
  3. For a standalone server, switch to a replica set to gain retryable-writes support.
  4. 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

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


AI-assisted analysis of mongodb/node-mongodb-native@3366c21a63 (2026-08-04). Data as JSON: /data/errors/cf2419c1d6e7ed9d.json. Report an issue: GitHub.