{"id":"12f8660881d374e4","repo":"mongodb/node-mongodb-native","slug":"operation-skip-requires-an-integer","errorCode":null,"errorMessage":"Operation \"skip\" requires an integer","messagePattern":"Operation \"skip\" requires an integer","errorType":"exception","errorClass":"MongoInvalidArgumentError","httpStatus":null,"severity":"error","filePath":"src/cursor/find_cursor.ts","lineNumber":491,"sourceCode":"    }\n\n    this.findOptions.limit = value;\n    return this;\n  }\n\n  /**\n   * Set the skip for the cursor.\n   *\n   * @param value - The skip for the cursor query.\n   */\n  skip(value: number): this {\n    this.throwIfInitialized();\n    if (this.findOptions.tailable) {\n      throw new MongoTailableCursorError('Tailable cursor does not support skip');\n    }\n\n    if (typeof value !== 'number') {\n      throw new MongoInvalidArgumentError('Operation \"skip\" requires an integer');\n    }\n\n    this.findOptions.skip = value;\n    return this;\n  }\n}\n","sourceCodeStart":473,"sourceCodeEnd":498,"githubUrl":"https://github.com/mongodb/node-mongodb-native/blob/3366c21a6311e02f1be91da982f9b93d3cce99a0/src/cursor/find_cursor.ts#L473-L498","documentation":"Thrown by FindCursor.skip() (MongoInvalidArgumentError) when value is not of type 'number'. skip must be an integer count of documents to ignore; strings, undefined, BigInt, or objects are rejected before dispatch.","triggerScenarios":"cursor.skip('10'), cursor.skip(undefined), cursor.skip(10n), cursor.skip(config.offset) where offset is a string.","commonSituations":"Pagination offsets read from query strings/env/config as strings; BigInt arithmetic; any-typed option bags.","solutions":["Coerce: cursor.skip(Number(val)) and ensure it is a finite integer","Type your pagination config so skip is number","Validate with Number.isInteger(Number(val)) before calling"],"exampleFix":"// before\ncursor.skip(req.query.offset);\n// after\ncursor.skip(Number(req.query.offset ?? 0));","handlingStrategy":"type-guard","validationCode":"function skipSafe(cursor, val) {\n  const n = Number(val);\n  if (!Number.isInteger(n)) throw new TypeError('skip must be an integer');\n  return cursor.skip(n);\n}","typeGuard":"const isIntegerNumber = (v) => typeof v === 'number' && Number.isInteger(v);","tryCatchPattern":null,"preventionTips":["Coerce pagination offsets from query strings with Number()","Type pagination config so skip is number","Validate Number.isInteger() before calling"],"tags":["find","skip","validation","typescript"],"analyzedSha":"3366c21a6311e02f1be91da982f9b93d3cce99a0","analyzedAt":"2026-08-04T13:40:15.335Z","schemaVersion":2}