{"id":"de81fc30cd394f63","repo":"mongodb/node-mongodb-native","slug":"runcommandcursor-does-not-support-readconcern-it-m","errorCode":null,"errorMessage":"RunCommandCursor does not support readConcern it must be attached to the command being run","messagePattern":"RunCommandCursor does not support readConcern it must be attached to the command being run","errorType":"exception","errorClass":"MongoAPIError","httpStatus":null,"severity":"error","filePath":"src/cursor/run_command_cursor.ts","lineNumber":106,"sourceCode":"  }\n\n  /**\n   * Controls the `getMore.batchSize` field\n   * @param batchSize - the number documents to return in the `nextBatch`\n   */\n  public setBatchSize(batchSize: number): this {\n    this.getMoreOptions.batchSize = batchSize;\n    return this;\n  }\n\n  /** Unsupported for RunCommandCursor */\n  public override clone(): never {\n    throw new MongoAPIError('Clone not supported, create a new cursor with db.runCursorCommand');\n  }\n\n  /** Unsupported for RunCommandCursor: readConcern must be configured directly on command document */\n  public override withReadConcern(_: ReadConcernLike): never {\n    throw new MongoAPIError(\n      'RunCommandCursor does not support readConcern it must be attached to the command being run'\n    );\n  }\n\n  /** Unsupported for RunCommandCursor: various cursor flags must be configured directly on command document */\n  public override addCursorFlag(_: string, __: boolean): never {\n    throw new MongoAPIError(\n      'RunCommandCursor does not support cursor flags, they must be attached to the command being run'\n    );\n  }\n\n  /**\n   * Unsupported for RunCommandCursor: maxTimeMS must be configured directly on command document\n   */\n  public override maxTimeMS(_: number): never {\n    throw new MongoAPIError(\n      'maxTimeMS must be configured on the command document directly, to configure getMore.maxTimeMS use cursor.setMaxTimeMS()'\n    );","sourceCodeStart":88,"sourceCodeEnd":124,"githubUrl":"https://github.com/mongodb/node-mongodb-native/blob/3366c21a6311e02f1be91da982f9b93d3cce99a0/src/cursor/run_command_cursor.ts#L88-L124","documentation":"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.","triggerScenarios":"Calling .withReadConcern({ level: 'majority' }) on a cursor returned by db.runCursorCommand().","commonSituations":"Shared configuration helpers that apply read concerns uniformly to all cursors; porting aggregation pipelines to runCursorCommand while preserving the concern.","solutions":["Embed readConcern in the command document: db.runCursorCommand({ ...cmd, readConcern: { level } })","Remove calls to withReadConcern on RunCommandCursor","Branch shared cursor configurators by cursor type"],"exampleFix":"// before\nconst c = db.runCursorCommand(cmd).withReadConcern({ level: 'majority' });\n// after\nconst c = db.runCursorCommand({ ...cmd, readConcern: { level: 'majority' } });","handlingStrategy":"type-guard","validationCode":"if (cursor instanceof RunCommandCursor) {\n  // attach readConcern to the command document instead\n  throw new Error('Use db.runCursorCommand({ ...cmd, readConcern }) instead');\n}","typeGuard":"function isRunCommandCursor(c: AbstractCursor): c is RunCommandCursor {\n  return c instanceof RunCommandCursor;\n}","tryCatchPattern":null,"preventionTips":["Embed readConcern in the command document","Avoid calling shared fluent setters on RunCommandCursor"],"tags":["cursor","read-concern","runcommandcursor","api-misuse"],"analyzedSha":"3366c21a6311e02f1be91da982f9b93d3cce99a0","analyzedAt":"2026-08-04T13:40:15.335Z","schemaVersion":2}