{"id":"1abbad61bc0c84b4","repo":"mongodb/node-mongodb-native","slug":"runcommandcursor-does-not-support-cursor-flags-th","errorCode":null,"errorMessage":"RunCommandCursor does not support cursor flags, they must be attached to the command being run","messagePattern":"RunCommandCursor does not support cursor flags, they must be attached to the command being run","errorType":"exception","errorClass":"MongoAPIError","httpStatus":null,"severity":"error","filePath":"src/cursor/run_command_cursor.ts","lineNumber":113,"sourceCode":"    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    );\n  }\n\n  /** Unsupported for RunCommandCursor: batchSize must be configured directly on command document */\n  public override batchSize(_: number): never {\n    throw new MongoAPIError(\n      'batchSize must be configured on the command document directly, to configure getMore.batchSize use cursor.setBatchSize()'\n    );","sourceCodeStart":95,"sourceCodeEnd":131,"githubUrl":"https://github.com/mongodb/node-mongodb-native/blob/3366c21a6311e02f1be91da982f9b93d3cce99a0/src/cursor/run_command_cursor.ts#L95-L131","documentation":"RunCommandCursor runs an opaque command document, so per-cursor wire flags (tailable, awaitData, noCursorTimeout, etc.) cannot be set via addCursorFlag(). They must be expressed as top-level fields of the command document, or for tailable/awaitData via the constructor options.","triggerScenarios":"Calling .addCursorFlag('noCursorTimeout', true) or .addCursorFlag('tailable', true) on a RunCommandCursor.","commonSituations":"Generic cursor tuners that flip flags; converting change-stream-like tailing code to runCursorCommand.","solutions":["Set tailable/awaitData via the options argument to db.runCursorCommand","Add the flag as a top-level field on the command document","Special-case RunCommandCursor in shared cursor configuration code"],"exampleFix":"// before\ncursor.addCursorFlag('noCursorTimeout', true);\n// after\nconst cursor = db.runCursorCommand({ ...cmd, noCursorTimeout: true });","handlingStrategy":"type-guard","validationCode":"if (cursor instanceof RunCommandCursor) {\n  throw new Error('Use the command document or constructor options for cursor flags');\n}","typeGuard":"function isRunCommandCursor(c: AbstractCursor): c is RunCommandCursor {\n  return c instanceof RunCommandCursor;\n}","tryCatchPattern":null,"preventionTips":["Set tailable/awaitData via runCursorCommand options","Put other flags directly on the command document"],"tags":["cursor","runcommandcursor","api-misuse"],"analyzedSha":"3366c21a6311e02f1be91da982f9b93d3cce99a0","analyzedAt":"2026-08-04T13:40:15.335Z","schemaVersion":2}