mongodb/node-mongodb-native · error · MongoParseError

serverMonitoringMode must be one of `auto`, `poll`, or `stre

Error message

serverMonitoringMode must be one of `auto`, `poll`, or `stream`

What it means

`serverMonitoringMode` selects the SDAM health-check strategy and must be one of the `ServerMonitoringMode` enum values: `auto`, `poll`, or `stream`. Any other value throws at src/connection_string.ts:1093.

Source

Thrown at src/connection_string.ts:1093

  retryReads: {
    default: true,
    type: 'boolean'
  },
  retryWrites: {
    default: true,
    type: 'boolean'
  },
  runtimeAdapters: {
    type: 'record'
  },
  serializeFunctions: {
    type: 'boolean'
  },
  serverMonitoringMode: {
    default: 'auto',
    transform({ values: [value] }) {
      if (!Object.values(ServerMonitoringMode).includes(value as any)) {
        throw new MongoParseError(
          'serverMonitoringMode must be one of `auto`, `poll`, or `stream`'
        );
      }
      return value;
    }
  },
  serverSelectionTimeoutMS: {
    default: 30000,
    type: 'uint'
  },
  servername: {
    type: 'string'
  },
  socketTimeoutMS: {
    // TODO(NODE-6491): deprecated: 'Please use timeoutMS instead',
    default: 0,
    type: 'uint'
  },

View on GitHub (pinned to 3366c21a63)

Solutions

  1. Use exactly 'auto', 'poll', or 'stream'
  2. Omit the option to use the default 'auto'
  3. Reference the ServerMonitoringMode enum instead of hardcoding strings

Example fix

// before
new MongoClient(uri, { serverMonitoringMode: 'polling' });
// after
new MongoClient(uri, { serverMonitoringMode: 'poll' });
Defensive patterns

Strategy: validation

Validate before calling

import { ServerMonitoringMode } from 'mongodb';
const VALID = new Set(Object.values(ServerMonitoringMode));
if (options.serverMonitoringMode != null && !VALID.has(options.serverMonitoringMode)) {
  throw new TypeError('serverMonitoringMode must be auto, poll, or stream');
}

Type guard

import { ServerMonitoringMode } from 'mongodb';
function isServerMonitoringMode(v) {
  return Object.values(ServerMonitoringMode).includes(v);
}

Prevention

When it happens

Trigger: `{ serverMonitoringMode: 'fast' }`; `{ serverMonitoringMode: 'websocket' }`; `{ serverMonitoringMode: 'polling' }`; `{ serverMonitoringMode: 'async' }`.

Common situations: Guessing mode names; using 'polling' instead of 'poll'; setting it to optimize latency without checking the enum.

Related errors


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