{"record":{"id":"248fb6cd8d4992a8","repo":"Automattic/mongoose","slug":"query-prototype-deleteone-no-longer-accepts-a-ca","errorCode":null,"errorMessage":"Query.prototype.deleteOne() no longer accepts a callback","messagePattern":"Query\\.prototype\\.deleteOne\\(\\) no longer accepts a callback","errorType":"exception","errorClass":"MongooseError","httpStatus":null,"severity":"error","filePath":"lib/query.js","lineNumber":3247,"sourceCode":" *\n * #### Example:\n *\n *     const res = await Character.deleteOne({ name: 'Eddard Stark' });\n *     // `1` if MongoDB deleted a doc, `0` if no docs matched the filter `{ name: ... }`\n *     res.deletedCount;\n *\n * @param {object|Query} [filter] mongodb selector\n * @param {object} [options] optional see [`Query.prototype.setOptions()`](https://mongoosejs.com/docs/api/query.html#Query.prototype.setOptions())\n * @param {boolean} [options.requireFilter=false] If true, throws an error if the filter is empty (`{}`)\n * @return {Query} this\n * @see DeleteResult https://mongodb.github.io/node-mongodb-native/7.0/interfaces/DeleteResult.html\n * @see deleteOne https://mongodb.github.io/node-mongodb-native/7.0/classes/Collection.html#deleteOne\n * @api public\n */\n\nQuery.prototype.deleteOne = function deleteOne(filter, options) {\n  if (typeof filter === 'function' || typeof options === 'function' || typeof arguments[2] === 'function') {\n    throw new MongooseError('Query.prototype.deleteOne() no longer accepts a callback');\n  }\n  this.op = 'deleteOne';\n  this.setOptions(options);\n\n  if (canMerge(filter)) {\n    this.merge(filter);\n\n    prepareDiscriminatorCriteria(this);\n  } else if (filter != null) {\n    this.error(new ObjectParameterError(filter, 'filter', 'deleteOne'));\n  }\n\n  return this;\n};\n\n/**\n * Internal thunk for `deleteOne()`\n *","sourceCodeStart":3229,"sourceCodeEnd":3265,"githubUrl":"https://github.com/Automattic/mongoose/blob/49cdab01366679723b487ecb754b38570f783289/lib/query.js#L3229-L3265","documentation":"Query.prototype.deleteOne(filter, options) throws when filter, options, or a third positional argument is a function — the Mongoose 7 removal of callback execution. The throw is synchronous at query-construction time, so legacy Model.deleteOne({}, cb) never reaches the database.","triggerScenarios":"Model.deleteOne({ _id }, (err) => {...}); .deleteOne(cb) with the callback in the filter slot; a function passed in the options slot.","commonSituations":"Cleanup and admin routes written against Mongoose 6; major-version upgrades; copy-pasted deletion snippets from old tutorials.","solutions":["Use await: const result = await Model.deleteOne({ _id }) and read result.deletedCount","Handle the rejected promise with try/catch or .catch()","During upgrade, grep for deleteOne( with trailing function arguments"],"exampleFix":"// before\nModel.deleteOne({ _id }, (err) => {\n  if (err) return next(err);\n  res.status(204).end();\n});\n\n// after\ntry {\n  await Model.deleteOne({ _id });\n  res.status(204).end();\n} catch (err) {\n  next(err);\n}","handlingStrategy":"validation","validationCode":"function deleteOneSafe(model, filter, options) {\n  if ([filter, options].some(v => typeof v === 'function')) {\n    throw new Error('deleteOne() is promise-only in Mongoose 7+');\n  }\n  return model.deleteOne(filter, options);\n}","typeGuard":"const isLegacyCallback = (v) => typeof v === 'function';","tryCatchPattern":"try {\n  const result = await Model.deleteOne({ _id });\n} catch (err) {\n  if (err?.message?.includes('no longer accepts a callback')) {\n    // fix the deleteOne call site that still passes a callback\n  }\n  throw err;\n}","preventionTips":["Await deleteOne and read result.deletedCount","Audit admin/cleanup routes for callback signatures when upgrading","Keep delete helpers in a data-access layer so signatures are checked in one place"],"tags":["mongoose","callback","promise","migration","breaking-change","delete"],"backgroundTag":"legacy-callback-removed","analyzedSha":"49cdab01366679723b487ecb754b38570f783289","analyzedAt":"2026-08-21T22:54:00.882Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}