{"id":"54dd61c943cbc5c8","repo":"mongodb/node-mongodb-native","slug":"a-collection-name-must-be-determined-before-getmor","errorCode":null,"errorMessage":"A collection name must be determined before getMore","messagePattern":"A collection name must be determined before getMore","errorType":"exception","errorClass":"MongoRuntimeError","httpStatus":null,"severity":"error","filePath":"src/operations/get_more.ts","lineNumber":65,"sourceCode":"    this.ns = ns;\n    this.cursorId = cursorId;\n    this.server = server;\n  }\n\n  override get commandName() {\n    return 'getMore' as const;\n  }\n\n  override buildCommand(_connection: Connection): Document {\n    if (this.cursorId == null || this.cursorId.isZero()) {\n      throw new MongoRuntimeError('Unable to iterate cursor with no id');\n    }\n\n    const collection = this.ns.collection;\n    if (collection == null) {\n      // Cursors should have adopted the namespace returned by MongoDB\n      // which should always defined a collection name (even a pseudo one, ex. db.aggregate())\n      throw new MongoRuntimeError('A collection name must be determined before getMore');\n    }\n\n    const getMoreCmd: GetMoreCommand = {\n      getMore: this.cursorId,\n      collection\n    };\n\n    if (typeof this.options.batchSize === 'number') {\n      getMoreCmd.batchSize = Math.abs(this.options.batchSize);\n    }\n\n    if (typeof this.options.maxAwaitTimeMS === 'number') {\n      getMoreCmd.maxTimeMS = this.options.maxAwaitTimeMS;\n    }\n\n    // we check for undefined specifically here to allow falsy values\n    // eslint-disable-next-line no-restricted-syntax\n    if (this.options.comment !== undefined) {","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/mongodb/node-mongodb-native/blob/3366c21a6311e02f1be91da982f9b93d3cce99a0/src/operations/get_more.ts#L47-L83","documentation":"Thrown by GetMoreOperation.buildCommand when this.ns.collection is null/undefined, so the getMore command cannot name a target collection. The driver expects every cursor to have adopted a fully-qualified namespace (db + collection) from the server's initial response; a missing collection name means that adoption did not happen. This is a MongoRuntimeError reflecting an inconsistent internal state, almost always triggered through aggregation or special cursors rather than normal find().","triggerScenarios":"Iterating a cursor from a command that does not bind a collection namespace (certain database-level aggregations, change streams on a client/database scope, or cursors constructed without a namespace). Also seen when internal namespace handling is bypassed or when a custom operation mis-sets the namespace. Normal collection.find()/aggregate() cursors should not hit this.","commonSituations":"Using db.aggregate() (no collection) and then mishandling the resulting cursor; driver upgrade where namespace adoption changed; manually constructed/internal cursor usage; rarely, a genuine driver bug worth reporting.","solutions":["If you used a database-level aggregation/change stream, ensure you iterate it through the standard async-iteration API and don't bypass the cursor wrapper.","Reproduce with collection-level operations (collection.aggregate) which always carry a namespace; switch if appropriate.","If the call path is standard and this still fires, capture the operation chain and file a driver bug with the MongoDB version and driver version.","Avoid constructing or mutating cursor namespaces directly from application code."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  await cursor.toArray();\n} catch (e) {\n  if (e instanceof MongoRuntimeError && /collection name/.test(e.message)) {\n    // switch to a collection-scoped operation, or report environment details\n  }\n  throw e;\n}","preventionTips":["Prefer collection.aggregate/find so cursors carry a namespace.","Avoid manual/internal cursor construction.","Keep the driver version aligned with your server version."],"tags":["cursor","getmore","namespace","runtime-error"],"analyzedSha":"3366c21a6311e02f1be91da982f9b93d3cce99a0","analyzedAt":"2026-08-04T13:40:15.335Z","schemaVersion":2}