{"record":{"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/dce7939f86fb283e167ad709955abedb7bf23124/src/operations/get_more.ts#L47-L83","documentation":"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.","triggerScenarios":"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.","commonSituations":"Driver bugs in namespace adoption; constructing cursors directly in tests without a namespace; edge cases with db-level aggregate/changeStream pipelines.","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."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  await cursor.next();\n} catch (err) {\n  if (err instanceof MongoRuntimeError && /collection name must be determined before getMore/.test(err.message)) {\n    // namespace not adopted; recreate the cursor via a collection-scoped query\n  } else throw err;\n}","preventionTips":["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."],"tags":["cursor","getmore","namespace","runtime","internal"],"backgroundTag":null,"analyzedSha":"dce7939f86fb283e167ad709955abedb7bf23124","analyzedAt":"2026-08-11T04:54:53.215Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}