{"id":"382848471a76f5f6","repo":"mongodb/node-mongodb-native","slug":"flag-flag-is-not-one-of-cursor-flags","errorCode":null,"errorMessage":"Flag ${flag} is not one of ${CURSOR_FLAGS}","messagePattern":"Flag (.+?) is not one of (.+?)","errorType":"exception","errorClass":"MongoInvalidArgumentError","httpStatus":null,"severity":"error","filePath":"src/cursor/abstract_cursor.ts","lineNumber":681,"sourceCode":"        // Note: previous versions of this logic used `array.push(...)`, which adds each item\n        // to the callstack.  For large arrays, this can exceed the maximum call size.\n        for (const doc of docs) {\n          array.push(doc);\n        }\n      }\n    }\n    return array;\n  }\n  /**\n   * Add a cursor flag to the cursor\n   *\n   * @param flag - The flag to set, must be one of following ['tailable', 'oplogReplay', 'noCursorTimeout', 'awaitData', 'partial' -.\n   * @param value - The flag boolean value.\n   */\n  addCursorFlag(flag: CursorFlag, value: boolean): this {\n    this.throwIfInitialized();\n    if (!CURSOR_FLAGS.includes(flag)) {\n      throw new MongoInvalidArgumentError(`Flag ${flag} is not one of ${CURSOR_FLAGS}`);\n    }\n\n    if (typeof value !== 'boolean') {\n      throw new MongoInvalidArgumentError(`Flag ${flag} must be a boolean value`);\n    }\n\n    this.cursorOptions[flag] = value;\n    return this;\n  }\n\n  /**\n   * Map all documents using the provided function\n   * If there is a transform set on the cursor, that will be called first and the result passed to\n   * this function's transform.\n   *\n   * @remarks\n   *\n   * **Note** Cursors use `null` internally to indicate that there are no more documents in the cursor. Providing a mapping","sourceCodeStart":663,"sourceCodeEnd":699,"githubUrl":"https://github.com/mongodb/node-mongodb-native/blob/3366c21a6311e02f1be91da982f9b93d3cce99a0/src/cursor/abstract_cursor.ts#L663-L699","documentation":"Thrown by cursor.addCursorFlag(flag, value) when flag is not one of CURSOR_FLAGS = ['tailable','oplogReplay','noCursorTimeout','awaitData','exhaust','partial']. The driver only allows the documented set of wire-protocol cursor flags.","triggerScenarios":"Calling addCursorFlag('noCursorTimeout') correctly works, but addCursorFlag('noTimeout'), addCursorFlag('maxTimeMS'), addCursorFlag('sort'), or any invented name throws. Also case mistakes like 'Tailable'.","commonSituations":"Confusing query options (sort, limit, batchSize) with cursor flags; pluralizing or abbreviating a flag name; using a name from another driver.","solutions":["Use only one of the six CURSOR_FLAGS. Prefer setting these via find() options (e.g. { tailable: true }) instead of addCursorFlag.","Check the exact spelling and case against CURSOR_FLAGS.","If the flag you want is not in the list, it is probably a query option, not a cursor flag."],"exampleFix":"// before\ncursor.addCursorFlag('noTimeout', true);\n// after\ncursor.addCursorFlag('noCursorTimeout', true);","handlingStrategy":"type-guard","validationCode":"import { CURSOR_FLAGS } from 'mongodb';\nif (!CURSOR_FLAGS.includes(flag)) throw new Error(`bad flag ${flag}`);","typeGuard":"import { CURSOR_FLAGS } from 'mongodb';\nfunction isCursorFlag(f): f is typeof CURSOR_FLAGS[number] {\n  return (CURSOR_FLAGS as readonly string[]).includes(f);\n}","tryCatchPattern":null,"preventionTips":["Prefer setting flags via find()/aggregate() options rather than addCursorFlag.","Derive allowed names from CURSOR_FLAGS instead of hardcoding.","Distinguish query options (sort/limit) from wire-protocol cursor flags."],"tags":["cursor","options","validation","misuse"],"analyzedSha":"3366c21a6311e02f1be91da982f9b93d3cce99a0","analyzedAt":"2026-08-04T13:40:15.335Z","schemaVersion":2}