{"id":"0fd8eea6278a1641","repo":"mongodb/node-mongodb-native","slug":"batchsize-must-be-configured-on-the-command-docume","errorCode":null,"errorMessage":"batchSize must be configured on the command document directly, to configure getMore.batchSize use cursor.setBatchSize()","messagePattern":"batchSize must be configured on the command document directly, to configure getMore\\.batchSize use cursor\\.setBatchSize\\(\\)","errorType":"exception","errorClass":"MongoAPIError","httpStatus":null,"severity":"error","filePath":"src/cursor/run_command_cursor.ts","lineNumber":129,"sourceCode":"  /** 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    );\n  }\n\n  /** @internal */\n  private db: Db;\n\n  /** @internal */\n  constructor(db: Db, command: Document, options: RunCursorCommandOptions = {}) {\n    super(db.client, ns(db.namespace), options);\n    this.db = db;\n    this.command = Object.freeze({ ...command });\n  }\n\n  /** @internal */\n  protected async _initialize(session: ClientSession): Promise<InitialCursorResponse> {\n    const operation = new RunCursorCommandOperation(this.db.s.namespace, this.command, {\n      ...this.cursorOptions,","sourceCodeStart":111,"sourceCodeEnd":147,"githubUrl":"https://github.com/mongodb/node-mongodb-native/blob/3366c21a6311e02f1be91da982f9b93d3cce99a0/src/cursor/run_command_cursor.ts#L111-L147","documentation":"For RunCommandCursor the initial command's batchSize must be embedded in the command document; the fluent batchSize() builder is disabled. To control getMore.batchSize, use cursor.setBatchSize().","triggerScenarios":"Calling .batchSize(100) on a RunCommandCursor returned by db.runCursorCommand().","commonSituations":"Porting pagination helpers that called .batchSize() on cursors; reusing generic cursor tuners.","solutions":["Add batchSize to the command document: db.runCursorCommand({ ...cmd, batchSize: 100 })","For getMore batchSize, call cursor.setBatchSize(100)","Branch shared configurators by cursor type"],"exampleFix":"// before\ndb.runCursorCommand(cmd).batchSize(100);\n// after\ndb.runCursorCommand({ ...cmd, batchSize: 100 });","handlingStrategy":"type-guard","validationCode":"if (cursor instanceof RunCommandCursor) {\n  throw new Error('Put batchSize on the command document; use cursor.setBatchSize() for getMore');\n}","typeGuard":"function isRunCommandCursor(c: AbstractCursor): c is RunCommandCursor {\n  return c instanceof RunCommandCursor;\n}","tryCatchPattern":null,"preventionTips":["Embed batchSize in the command document","Use cursor.setBatchSize() for getMore-only control"],"tags":["cursor","runcommandcursor","api-misuse"],"analyzedSha":"3366c21a6311e02f1be91da982f9b93d3cce99a0","analyzedAt":"2026-08-04T13:40:15.335Z","schemaVersion":2}