{"record":{"id":"def91720d222128f","repo":"Automattic/mongoose","slug":"model-find-no-longer-accepts-a-callback","errorCode":null,"errorMessage":"Model.find() no longer accepts a callback","messagePattern":"Model\\.find\\(\\) no longer accepts a callback","errorType":"exception","errorClass":"MongooseError","httpStatus":null,"severity":"error","filePath":"lib/model.js","lineNumber":2126,"sourceCode":" *     await MyModel.find({ name: /john/i }, 'name friends').exec();\n *\n *     // passing options\n *     await MyModel.find({ name: /john/i }, null, { skip: 10 }).exec();\n *\n * @param {object|ObjectId} filter\n * @param {object|string|string[]} [projection] optional fields to return, see [`Query.prototype.select()`](https://mongoosejs.com/docs/api/query.html#Query.prototype.select())\n * @param {object} [options] optional see [`Query.prototype.setOptions()`](https://mongoosejs.com/docs/api/query.html#Query.prototype.setOptions())\n * @param {boolean} [options.translateAliases=null] If set to `true`, translates any schema-defined aliases in `filter`, `projection`, `update`, and `distinct`. Throws an error if there are any conflicts where both alias and raw property are defined on the same object.\n * @return {Query}\n * @see field selection https://mongoosejs.com/docs/api/query.html#Query.prototype.select()\n * @see query casting https://mongoosejs.com/docs/tutorials/query_casting.html\n * @api public\n */\n\nModel.find = function find(conditions, projection, options) {\n  _checkContext(this, 'find');\n  if (typeof arguments[0] === 'function' || typeof arguments[1] === 'function' || typeof arguments[2] === 'function' || typeof arguments[3] === 'function') {\n    throw new MongooseError('Model.find() no longer accepts a callback');\n  }\n\n  const mq = new this.Query({}, {}, this, this.$__collection);\n  mq.select(projection);\n  mq.setOptions(options);\n\n  return mq.find(conditions);\n};\n\n/**\n * Finds a single document by its _id field. `findById(id)` is equivalent to `findOne({ _id: id })`.\n *\n * The `id` is cast based on the Schema before sending the command.\n *\n * This function triggers the following middleware.\n *\n * - `findOne()`\n *","sourceCodeStart":2108,"sourceCodeEnd":2144,"githubUrl":"https://github.com/Automattic/mongoose/blob/49cdab01366679723b487ecb754b38570f783289/lib/model.js#L2108-L2144","documentation":"Model.find(conditions, projection, options) is the core query static; Mongoose 7 removed its callback form, so a function in any of the first four argument slots throws synchronously and no Query is returned. The result comes from awaiting the Query or calling .exec().","triggerScenarios":"`User.find({ age: { $gte: 18 } }, 'name', (err, docs) => ...)`; `User.find(cb)`; any of the 4 positional slots receiving a function.","commonSituations":"The single most common hit when upgrading mongoose 6 to 7+: find() calls are ubiquitous; old tutorials and generated CRUD code are callback-based.","solutions":["Await the query: `const users = await User.find({ age: { $gte: 18 } }, 'name');`","Or `User.find({}).exec().then(...)`","Automate the sweep: grep for `\\.find\\(.*=>` and `\\.find\\([^)]*,\\s*function` and migrate all matches in one pass"],"exampleFix":"// before\nUser.find({ role: 'admin' }, (err, admins) => { if (err) throw err; ... });\n\n// after\nconst admins = await User.find({ role: 'admin' });","handlingStrategy":"validation","validationCode":"const isFn = (a) => typeof a === 'function';\nif ([conditions, projection, options].some(isFn)) {\n  throw new TypeError('find() is promise-only');\n}\nconst docs = await User.find(conditions, projection, options);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Do the callback-to-promise migration as its own commit before bumping mongoose major — find() has the most call sites","Enable no-floating-promises in ESLint so an un-awaited Query is caught statically"],"tags":["mongoose","callback-removed","promise","query","migration"],"backgroundTag":"mongoose-callback-removed","analyzedSha":"49cdab01366679723b487ecb754b38570f783289","analyzedAt":"2026-08-21T22:54:00.882Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}