{"record":{"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/dce7939f86fb283e167ad709955abedb7bf23124/src/cursor/run_command_cursor.ts#L111-L147","documentation":"Thrown by RunCommandCursor.batchSize because the inherited method would set batchSize for the initial cursor-creating command, but the command document is frozen and sent verbatim. The initial batchSize must live on the command; getMore.batchSize is set via cursor.setBatchSize. The override prevents a silent no-op.","triggerScenarios":"Calling cursor.batchSize(100) on a RunCommandCursor; generic cursor setup that sets batchSize on every cursor; tuning batch sizes for a runCursorCommand stream.","commonSituations":"Sharing cursor-tuning helpers across find/aggregate/runCommand; refactoring from find().batchSize() patterns.","solutions":["For the initial command: put batchSize on the command document, db.runCursorCommand({ find: 'coll', filter: {}, batchSize: 100 }).","For getMore.batchSize: call cursor.setBatchSize(100) which sets getMoreOptions.batchSize.","Drop the inherited batchSize() call on RunCommandCursor."],"exampleFix":"// before\ncursor.batchSize(100);\n\n// after\ndb.runCursorCommand({ find: 'coll', filter: {}, cursor: { batchSize: 100 } });\n// or for getMore:\ncursor.setBatchSize(100);","handlingStrategy":"validation","validationCode":"function applyBatchSize(db, cursor, cmd, size, scope) {\n  if (scope === 'getMore') return cursor.setBatchSize(size);\n  return db.runCursorCommand({ ...cmd, cursor: { ...(cmd.cursor ?? {}), batchSize: size } });\n}","typeGuard":"function isRunCommandCursor(cursor) { return cursor instanceof RunCommandCursor; }","tryCatchPattern":null,"preventionTips":["Put initial batchSize on the command document (cursor: { batchSize }).","Use cursor.setBatchSize only for getMore.batchSize on tailable-await streams."],"tags":["run-command-cursor","batch-size","unsupported"],"backgroundTag":null,"analyzedSha":"dce7939f86fb283e167ad709955abedb7bf23124","analyzedAt":"2026-08-11T04:54:53.215Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}