{"record":{"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/dce7939f86fb283e167ad709955abedb7bf23124/src/cursor/find_cursor.ts#L473-L498","documentation":"Thrown by FindCursor.skip when the value argument is not of type 'number'. The server requires an integer skip count and the driver type-checks before storing it on findOptions. Strings, booleans, undefined, and objects are rejected.","triggerScenarios":"cursor.skip('20'); cursor.skip(parseInt(input)) returning NaN; cursor.skip(undefinedVar); passing pagination offset typed as string | number without narrowing.","commonSituations":"Pagination offsets from URL query strings; Number/parseInt returning NaN; optional config fields destructured without a default.","solutions":["Coerce and validate: const n = Number(value); if (!Number.isFinite(n)) throw ...; cursor.skip(n).","Pass skip through find options: collection.find({}, { skip: 20 }).","Guard the call: if (typeof value === 'number') cursor.skip(value)."],"exampleFix":"// before\ncursor.skip(req.query.offset); // string\n\n// after\nconst skip = Number(req.query.offset);\nif (Number.isFinite(skip)) cursor.skip(skip);","handlingStrategy":"type-guard","validationCode":"function safeSkip(cursor, value) {\n  const n = Number(value);\n  if (!Number.isFinite(n)) throw new TypeError('skip must be a finite number');\n  return cursor.skip(n);\n}","typeGuard":"function isFiniteInteger(v) { return typeof v === 'number' && Number.isFinite(v) && Number.isInteger(v); }","tryCatchPattern":null,"preventionTips":["Coerce offset strings from request payloads with Number() and validate finiteness.","Pass skip through find options to centralize validation."],"tags":["find","skip","type-validation"],"backgroundTag":null,"analyzedSha":"dce7939f86fb283e167ad709955abedb7bf23124","analyzedAt":"2026-08-11T04:54:53.215Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}