mongodb/node-mongodb-native · error · MongoRuntimeError
A collection name must be determined before getMore
Error message
A collection name must be determined before getMore
What it means
Thrown as a MongoRuntimeError by GetMoreOperation.buildCommand when the cursor's namespace has no collection name (this.ns.collection == null). getMore must address a concrete collection, and the cursor should have adopted the namespace returned by the server. A null collection indicates the cursor namespace was never set or was corrupted, which is an internal/driver-level defect rather than typical user input.
Solutions
- If reproducing in user code, ensure you create cursors via the standard APIs (collection.find/aggregate) which set the namespace.
- Report the reproduction to the driver maintainers; this guard typically signals an internal defect.
- Avoid manually constructing or mutating cursor namespaces.
Defensive patterns
Strategy: try-catch
Try / catch
try {
await cursor.next();
} catch (err) {
if (err instanceof MongoRuntimeError && /collection name must be determined before getMore/.test(err.message)) {
// namespace not adopted; recreate the cursor via a collection-scoped query
} else throw err;
} Prevention
- Create cursors only through collection.find()/collection.aggregate() so namespaces are set.
- Avoid constructing or mutating cursor namespaces manually.
- Report persistent reproductions to driver maintainers; this is an internal guard.
When it happens
Trigger: Issuing getMore on a cursor whose namespace.collection is null/undefined. This can happen with certain collection-less commands (e.g. some aggregate against a database) where the server's namespace adoption did not populate a pseudo collection name, or via internal cursor misuse.
Common situations: Driver bugs in namespace adoption; constructing cursors directly in tests without a namespace; edge cases with db-level aggregate/changeStream pipelines.
Related errors
- A collection name must be determined before killCursors
- Unable to iterate cursor with no id
- An unexpected error type
- A query document must be specified for query
- Argument for maxTimeMS must be a number
AI-assisted analysis of mongodb/node-mongodb-native@dce7939f86 (2026-08-11).
Data as JSON: /api/errors/54dd61c943cbc5c8.
Report an issue: GitHub.
Appendix: source
Thrown at src/operations/get_more.ts:65
this.ns = ns;
this.cursorId = cursorId;
this.server = server;
}
override get commandName() {
return 'getMore' as const;
}
override buildCommand(_connection: Connection): Document {
if (this.cursorId == null || this.cursorId.isZero()) {
throw new MongoRuntimeError('Unable to iterate cursor with no id');
}
const collection = this.ns.collection;
if (collection == null) {
// Cursors should have adopted the namespace returned by MongoDB
// which should always defined a collection name (even a pseudo one, ex. db.aggregate())
throw new MongoRuntimeError('A collection name must be determined before getMore');
}
const getMoreCmd: GetMoreCommand = {
getMore: this.cursorId,
collection
};
if (typeof this.options.batchSize === 'number') {
getMoreCmd.batchSize = Math.abs(this.options.batchSize);
}
if (typeof this.options.maxAwaitTimeMS === 'number') {
getMoreCmd.maxTimeMS = this.options.maxAwaitTimeMS;
}
// we check for undefined specifically here to allow falsy values
// eslint-disable-next-line no-restricted-syntax
if (this.options.comment !== undefined) {View on GitHub (pinned to dce7939f86)