{"record":{"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/dce7939f86fb283e167ad709955abedb7bf23124/src/cursor/run_command_cursor.ts#L88-L124","documentation":"Thrown by RunCommandCursor.withReadConcern because the cursor cannot inject readConcern into the command post-hoc. The command document passed to db.runCursorCommand is frozen and sent verbatim, so any readConcern must already be present on that document. This override exists to prevent a silent no-op where withReadConcern would appear to succeed but the server would ignore it.","triggerScenarios":"Calling cursor.withReadConcern('majority') on a RunCommandCursor; generic middleware that applies readConcern to every cursor; attempting to set a read concern after creating the cursor.","commonSituations":"Sharing readConcern-handling code across find/aggregate/runCommand cursors; building a query abstraction that always sets readConcern.","solutions":["Put readConcern directly on the command: db.runCursorCommand({ find: 'coll', filter: {}, readConcern: { level: 'majority' } }).","Drop the withReadConcern call on RunCommandCursor.","Branch generic cursor middleware to skip withReadConcern when the cursor is a RunCommandCursor."],"exampleFix":"// before\ncursor.withReadConcern('majority');\n\n// after\ndb.runCursorCommand({\n  aggregate: 'coll',\n  pipeline: [],\n  cursor: {},\n  readConcern: { level: 'majority' }\n});","handlingStrategy":"validation","validationCode":"function buildCommandWithReadConcern(cmd, level) {\n  return { ...cmd, readConcern: { level } };\n}\n// usage: db.runCursorCommand(buildCommandWithReadConcern(cmd, 'majority'))","typeGuard":"function isRunCommandCursor(cursor) { return cursor instanceof RunCommandCursor; }","tryCatchPattern":null,"preventionTips":["Attach readConcern to the command document before calling runCursorCommand.","Skip withReadConcern in shared middleware when the cursor is a RunCommandCursor."],"tags":["run-command-cursor","read-concern","unsupported"],"backgroundTag":null,"analyzedSha":"dce7939f86fb283e167ad709955abedb7bf23124","analyzedAt":"2026-08-11T04:54:53.215Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}