{"record":{"id":"65fcc3d21632c7ad","repo":"Automattic/mongoose","slug":"aggregationcursor-prototype-close-no-longer-acce","errorCode":null,"errorMessage":"AggregationCursor.prototype.close() no longer accepts a callback","messagePattern":"AggregationCursor\\.prototype\\.close\\(\\) no longer accepts a callback","errorType":"exception","errorClass":"MongooseError","httpStatus":null,"severity":"error","filePath":"lib/cursor/aggregationCursor.js","lineNumber":240,"sourceCode":"AggregationCursor.prototype._markError = function(error) {\n  this._error = error;\n  return this;\n};\n\n/**\n * Marks this cursor as closed. Will stop streaming and subsequent calls to\n * `next()` will error.\n *\n * @return {Promise}\n * @api public\n * @method close\n * @emits \"close\"\n * @see AggregationCursor.close https://mongodb.github.io/node-mongodb-native/7.0/classes/AggregationCursor.html#close\n */\n\nAggregationCursor.prototype.close = async function close() {\n  if (typeof arguments[0] === 'function') {\n    throw new MongooseError('AggregationCursor.prototype.close() no longer accepts a callback');\n  }\n  try {\n    await this.cursor.close();\n  } catch (error) {\n    this.listeners('error').length > 0 && this.emit('error', error);\n    throw error;\n  }\n  this.emit('close');\n};\n\n/**\n * Marks this cursor as destroyed. Will stop streaming and subsequent calls to\n * `next()` will error.\n *\n * @return {this}\n * @api private\n * @method _destroy\n */","sourceCodeStart":222,"sourceCodeEnd":258,"githubUrl":"https://github.com/Automattic/mongoose/blob/49cdab01366679723b487ecb754b38570f783289/lib/cursor/aggregationCursor.js#L222-L258","documentation":"Mongoose 7 removed callback support, mirroring the MongoDB driver. AggregationCursor#close() is now an async method returning a Promise; passing a function as the first argument throws immediately so legacy call sites fail loudly instead of silently never invoking the callback.","triggerScenarios":"aggCursor.close(() => {}) or aggCursor.close(function (err) {...}) — any function passed as the first argument to close().","commonSituations":"Upgrading an app from Mongoose 6 or earlier to 7+ without migrating cursor code; copy-pasting pre-2022 tutorials that use the callback style.","solutions":["Replace cursor.close(cb) with await cursor.close() and handle errors with try/catch or .catch()","If a callback API must be kept outward, shim it: cursor.close().then(() => cb(null), cb)","During the Mongoose 7 migration, sweep the codebase for cursor close calls that pass a function"],"exampleFix":"// before\naggCursor.close(function (err) {\n  if (err) console.error(err);\n});\n\n// after\ntry {\n  await aggCursor.close();\n} catch (err) {\n  console.error(err);\n}","handlingStrategy":"validation","validationCode":"function closeCursor(cursor, ...args) {\n  if (args.some(a => typeof a === 'function')) {\n    throw new TypeError('close() takes no callback; await the returned promise');\n  }\n  return cursor.close();\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never pass functions to cursor lifecycle methods in Mongoose 7+ code","Run a migration grep for callback-style cursor calls before upgrading major versions","Keep cursor utilities promise-only and wrap at the edge if legacy callback callers exist"],"tags":["aggregation-cursor","callback","promise","mongoose-7","migration"],"backgroundTag":"callback-api-removed","analyzedSha":"49cdab01366679723b487ecb754b38570f783289","analyzedAt":"2026-08-21T22:54:00.882Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}