mongodb/node-mongodb-native · error · MongoInvalidArgumentError
Operation "skip" requires an integer
Error message
Operation "skip" requires an integer
What it means
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.
Source
Thrown at src/cursor/find_cursor.ts:491
}
this.findOptions.limit = value;
return this;
}
/**
* Set the skip for the cursor.
*
* @param value - The skip for the cursor query.
*/
skip(value: number): this {
this.throwIfInitialized();
if (this.findOptions.tailable) {
throw new MongoTailableCursorError('Tailable cursor does not support skip');
}
if (typeof value !== 'number') {
throw new MongoInvalidArgumentError('Operation "skip" requires an integer');
}
this.findOptions.skip = value;
return this;
}
}
View on GitHub (pinned to 3366c21a63)
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
Example fix
// before cursor.skip(req.query.offset); // after cursor.skip(Number(req.query.offset ?? 0));
Defensive patterns
Strategy: type-guard
Validate before calling
function skipSafe(cursor, val) {
const n = Number(val);
if (!Number.isInteger(n)) throw new TypeError('skip must be an integer');
return cursor.skip(n);
} Type guard
const isIntegerNumber = (v) => typeof v === 'number' && Number.isInteger(v);
Prevention
- Coerce pagination offsets from query strings with Number()
- Type pagination config so skip is number
- Validate Number.isInteger() before calling
When it happens
Trigger: cursor.skip('10'), cursor.skip(undefined), cursor.skip(10n), cursor.skip(config.offset) where offset is a string.
Common situations: Pagination offsets read from query strings/env/config as strings; BigInt arithmetic; any-typed option bags.
Related errors
- Argument for maxAwaitTimeMS must be a number
- Argument for maxTimeMS must be a number
- Operation "limit" requires an integer
- Option "keyAltNames" must be an array of strings, but was of
- Option "keyAltNames" must be an array of strings, but item a
AI-assisted analysis of mongodb/node-mongodb-native@3366c21a63 (2026-08-04).
Data as JSON: /data/errors/12f8660881d374e4.json.
Report an issue: GitHub.