mongodb/node-mongodb-native · error · MongoAPIError

RunCommandCursor does not support readConcern it must be att

Error message

RunCommandCursor does not support readConcern it must be attached to the command being run

What it means

RunCommandCursor executes a raw command document, so readConcern cannot be applied through the fluent withReadConcern() builder. The concern level must be embedded as a field of the command itself (e.g. { readConcern: { level: 'majority' } }), because the driver passes the command through verbatim.

Source

Thrown at src/cursor/run_command_cursor.ts:106

  }

  /**
   * Controls the `getMore.batchSize` field
   * @param batchSize - the number documents to return in the `nextBatch`
   */
  public setBatchSize(batchSize: number): this {
    this.getMoreOptions.batchSize = batchSize;
    return this;
  }

  /** Unsupported for RunCommandCursor */
  public override clone(): never {
    throw new MongoAPIError('Clone not supported, create a new cursor with db.runCursorCommand');
  }

  /** Unsupported for RunCommandCursor: readConcern must be configured directly on command document */
  public override withReadConcern(_: ReadConcernLike): never {
    throw new MongoAPIError(
      'RunCommandCursor does not support readConcern it must be attached to the command being run'
    );
  }

  /** Unsupported for RunCommandCursor: various cursor flags must be configured directly on command document */
  public override addCursorFlag(_: string, __: boolean): never {
    throw new MongoAPIError(
      'RunCommandCursor does not support cursor flags, they must be attached to the command being run'
    );
  }

  /**
   * Unsupported for RunCommandCursor: maxTimeMS must be configured directly on command document
   */
  public override maxTimeMS(_: number): never {
    throw new MongoAPIError(
      'maxTimeMS must be configured on the command document directly, to configure getMore.maxTimeMS use cursor.setMaxTimeMS()'
    );

View on GitHub (pinned to 3366c21a63)

Solutions

  1. Embed readConcern in the command document: db.runCursorCommand({ ...cmd, readConcern: { level } })
  2. Remove calls to withReadConcern on RunCommandCursor
  3. Branch shared cursor configurators by cursor type

Example fix

// before
const c = db.runCursorCommand(cmd).withReadConcern({ level: 'majority' });
// after
const c = db.runCursorCommand({ ...cmd, readConcern: { level: 'majority' } });
Defensive patterns

Strategy: type-guard

Validate before calling

if (cursor instanceof RunCommandCursor) {
  // attach readConcern to the command document instead
  throw new Error('Use db.runCursorCommand({ ...cmd, readConcern }) instead');
}

Type guard

function isRunCommandCursor(c: AbstractCursor): c is RunCommandCursor {
  return c instanceof RunCommandCursor;
}

Prevention

When it happens

Trigger: Calling .withReadConcern({ level: 'majority' }) on a cursor returned by db.runCursorCommand().

Common situations: Shared configuration helpers that apply read concerns uniformly to all cursors; porting aggregation pipelines to runCursorCommand while preserving the concern.

Related errors


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