{"record":{"id":"beb5650fbb7a2148","repo":"Automattic/mongoose","slug":"mongoose-beb565","errorCode":"MONGOOSE","errorMessage":"mongoose: the `new` option for `findOneAndUpdate()` and `findOneAndReplace()` is deprecated. Use `returnDocument: ${replacement}` instead.","messagePattern":"mongoose: the `new` option for `findOneAndUpdate\\(\\)` and `findOneAndReplace\\(\\)` is deprecated\\. Use `returnDocument: (.+?)` instead\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/query.js","lineNumber":3995,"sourceCode":" * @return {Query} this\n * @see findAndModify command https://www.mongodb.com/docs/manual/reference/command/findAndModify/\n * @api public\n */\n\nQuery.prototype.findByIdAndDelete = function(id, options) {\n  return this.findOneAndDelete({ _id: id }, options);\n};\n\n/**\n * Support the `new` option as an alternative to `returnOriginal` for backwards\n * compat.\n * @api private\n */\n\nfunction convertNewToReturnDocument(options) {\n  if ('new' in options) {\n    const replacement = options['new'] ? '\\'after\\'' : '\\'before\\'';\n    utils.warn(\n      'mongoose: the `new` option for `findOneAndUpdate()` and `findOneAndReplace()` is deprecated. ' +\n      'Use `returnDocument: ' + replacement + '` instead.'\n    );\n    options.returnDocument = options['new'] ? 'after' : 'before';\n    delete options['new'];\n  }\n  if ('returnOriginal' in options) {\n    const replacement = options['returnOriginal'] ? '\\'before\\'' : '\\'after\\'';\n    utils.warn(\n      'mongoose: the `returnOriginal` option for `findOneAndUpdate()` and `findOneAndReplace()` is deprecated. ' +\n      'Use `returnDocument: ' + replacement + '` instead.'\n    );\n    options.returnDocument = options['returnOriginal'] ? 'before' : 'after';\n    delete options['returnOriginal'];\n  }\n  // Temporary since driver 4.0.0-beta does not support `returnDocument`\n  if (typeof options.returnDocument === 'string') {\n    options.returnOriginal = options.returnDocument === 'before';","sourceCodeStart":3977,"sourceCodeEnd":4013,"githubUrl":"https://github.com/Automattic/mongoose/blob/49cdab01366679723b487ecb754b38570f783289/lib/query.js#L3977-L4013","documentation":"Error \"mongoose: the `new` option for `findOneAndUpdate()` and `findOneAndReplace()` is deprecated. Use `returnDocument: ${replacement}` instead.\" thrown in Automattic/mongoose.","triggerScenarios":"Thrown at lib/query.js:3995 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"49cdab01366679723b487ecb754b38570f783289","analyzedAt":"2026-08-21T22:54:00.882Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}