{"record":{"id":"a07a732138c0f335","repo":"mongodb/node-mongodb-native","slug":"a-collection-name-must-be-determined-before-killcu","errorCode":null,"errorMessage":"A collection name must be determined before killCursors","messagePattern":"A collection name must be determined before killCursors","errorType":"exception","errorClass":"MongoRuntimeError","httpStatus":null,"severity":"error","filePath":"src/operations/kill_cursors.ts","lineNumber":41,"sourceCode":"  cursorId: Long;\n\n  constructor(cursorId: Long, ns: MongoDBNamespace, server: Server, options: OperationOptions) {\n    super(options);\n    this.ns = ns;\n    this.cursorId = cursorId;\n    this.server = server;\n  }\n\n  override get commandName() {\n    return 'killCursors' as const;\n  }\n\n  override buildCommand(_connection: Connection, _session?: ClientSession): KillCursorsCommand {\n    const killCursors = this.ns.collection;\n    if (killCursors == 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 killCursors');\n    }\n\n    const killCursorsCommand: KillCursorsCommand = {\n      killCursors,\n      cursors: [this.cursorId]\n    };\n\n    return killCursorsCommand;\n  }\n\n  override buildOptions(timeoutContext: TimeoutContext): ServerCommandOptions {\n    return {\n      session: this.session,\n      timeoutContext\n    };\n  }\n\n  override handleError(_error: MongoError): void {","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/mongodb/node-mongodb-native/blob/dce7939f86fb283e167ad709955abedb7bf23124/src/operations/kill_cursors.ts#L23-L59","documentation":"Thrown as a MongoRuntimeError by KillCursorsOperation.buildCommand when the cursor's namespace has no collection name (this.ns.collection == null). killCursors must name a collection, and a null collection indicates the cursor namespace was not set, which is an internal-state problem rather than user input.","triggerScenarios":"The driver attempts to clean up (kill) a cursor whose namespace.collection is null/undefined. Typically arises during cursor cleanup for collection-less or namespace-deficient cursors, or from internal/test construction of cursors.","commonSituations":"Driver-internal cleanup paths; test harnesses that build cursors without full namespaces; edge cases with db-level operations.","solutions":["Use standard collection-scoped APIs to create cursors so the namespace is populated.","Report persistent reproductions to the driver maintainers as an internal defect.","Do not manually construct KillCursorsOperation with incomplete namespaces in tests."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  await cursor.close();\n} catch (err) {\n  if (err instanceof MongoRuntimeError && /collection name must be determined before killCursors/.test(err.message)) {\n    // cleanup of a namespace-deficient cursor; ignore, the cursor is local-only\n  } else throw err;\n}","preventionTips":["Use collection-scoped APIs to create cursors so the namespace is always populated.","Do not build KillCursorsOperation with incomplete namespaces in tests.","Treat persistent occurrences as a driver defect to report."],"tags":["cursor","kill-cursors","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"}