{"record":{"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/dce7939f86fb283e167ad709955abedb7bf23124/src/cursor/run_command_cursor.ts#L95-L131","documentation":"Thrown by RunCommandCursor.addCursorFlag because wire-protocol cursor flags (tailable, awaitData, noCursorTimeout, oplogReplay, exhaust, partial) must be part of the command document sent by runCursorCommand, not applied after construction. The command is frozen at construction time, so the driver rejects this override rather than silently ignoring the flag.","triggerScenarios":"Calling cursor.addCursorFlag('tailable', true) or cursor.addCursorFlag('awaitData', true) on a RunCommandCursor; generic cursor setup that sets awaitData for change-like streams.","commonSituations":"Building a tailable raw-command cursor for change-like streaming; reusing find-cursor setup helpers verbatim.","solutions":["Put the flag directly on the command document: db.runCursorCommand({ find: 'coll', filter: {}, tailable: true, awaitData: true }).","Use the tailable/awaitData options of RunCursorCommandOptions at construction: db.runCursorCommand(cmd, { tailable: true, awaitData: true }).","Drop the addCursorFlag call for RunCommandCursor."],"exampleFix":"// before\ncursor.addCursorFlag('awaitData', true);\n\n// after\ndb.runCursorCommand(cmd, { tailable: true, awaitData: true });","handlingStrategy":"validation","validationCode":"function buildTailableCommand(cmd, flags) {\n  return { ...cmd, ...flags }; // e.g. { tailable: true, awaitData: true }\n}\n// usage: db.runCursorCommand(buildTailableCommand(cmd, { tailable: true, awaitData: true }))","typeGuard":"function isRunCommandCursor(cursor) { return cursor instanceof RunCommandCursor; }","tryCatchPattern":null,"preventionTips":["Set cursor flags on the command document or via RunCursorCommandOptions, not addCursorFlag.","Branch generic cursor setup to skip addCursorFlag for RunCommandCursor."],"tags":["run-command-cursor","cursor-flags","tailable","unsupported"],"backgroundTag":null,"analyzedSha":"dce7939f86fb283e167ad709955abedb7bf23124","analyzedAt":"2026-08-11T04:54:53.215Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}