mongodb/node-mongodb-native · error · MongoInvalidArgumentError
Stream start (${options.start}) must not be greater than str
Error message
Stream start (${options.start}) must not be greater than stream end (${options.end}) What it means
handleStartOption enforces that start is not greater than end. A reversed range would produce a nonsensical byte window.
Source
Thrown at src/gridfs/download.ts:445
});
}
function handleStartOption(
stream: GridFSBucketReadStream,
doc: Document,
options: GridFSBucketReadStreamOptions
): number {
if (options && options.start != null) {
if (options.start > doc.length) {
throw new MongoInvalidArgumentError(
`Stream start (${options.start}) must not be more than the length of the file (${doc.length})`
);
}
if (options.start < 0) {
throw new MongoInvalidArgumentError(`Stream start (${options.start}) must not be negative`);
}
if (options.end != null && options.end < options.start) {
throw new MongoInvalidArgumentError(
`Stream start (${options.start}) must not be greater than stream end (${options.end})`
);
}
stream.s.bytesRead = Math.floor(options.start / doc.chunkSize) * doc.chunkSize;
stream.s.expected = Math.floor(options.start / doc.chunkSize);
return options.start - stream.s.bytesRead;
}
throw new MongoInvalidArgumentError('Start option must be defined');
}
function handleEndOption(
stream: GridFSBucketReadStream,
doc: Document,
cursor: FindCursor<GridFSChunk>,
options: GridFSBucketReadStreamOptions
) {View on GitHub (pinned to 3366c21a63)
Solutions
- Order the arguments so start <= end before opening the stream
- Normalize with { start: Math.min(a,b), end: Math.max(a,b) }
- Validate user-supplied ranges
Example fix
// before
{ start: 200, end: 100 }
// after
{ start: Math.min(a, b), end: Math.max(a, b) } Defensive patterns
Strategy: validation
Validate before calling
if (start > end) [start, end] = [end, start];
Prevention
- Normalize ranges so start <= end before opening the stream
- Validate user-supplied slice bounds
When it happens
Trigger: bucket.openDownloadStream(id, { start: 200, end: 100 }).
Common situations: Swapped arguments; bad slice math; user input ordered high-to-low.
Related errors
- Stream start (${options.start}) must not be more than the le
- Stream start (${options.start}) must not be negative
- Stream end (${options.end}) must not be more than the length
- Stream end (${options.end}) must not be negative
- Options cannot be changed after the stream is initialized
AI-assisted analysis of mongodb/node-mongodb-native@3366c21a63 (2026-08-04).
Data as JSON: /data/errors/d784bd48b0d739bf.json.
Report an issue: GitHub.