Automattic/mongoose · error
MONGOOSE
MONGOOSE
Error message
mongoose: the `new` option for `findOneAndUpdate()` and `findOneAndReplace()` is deprecated. Use `returnDocument: ${replacement}` instead. What it means
Error "mongoose: the `new` option for `findOneAndUpdate()` and `findOneAndReplace()` is deprecated. Use `returnDocument: ${replacement}` instead." thrown in Automattic/mongoose.
Source
Thrown at lib/query.js:3995
* @return {Query} this
* @see findAndModify command https://www.mongodb.com/docs/manual/reference/command/findAndModify/
* @api public
*/
Query.prototype.findByIdAndDelete = function(id, options) {
return this.findOneAndDelete({ _id: id }, options);
};
/**
* Support the `new` option as an alternative to `returnOriginal` for backwards
* compat.
* @api private
*/
function convertNewToReturnDocument(options) {
if ('new' in options) {
const replacement = options['new'] ? '\'after\'' : '\'before\'';
utils.warn(
'mongoose: the `new` option for `findOneAndUpdate()` and `findOneAndReplace()` is deprecated. ' +
'Use `returnDocument: ' + replacement + '` instead.'
);
options.returnDocument = options['new'] ? 'after' : 'before';
delete options['new'];
}
if ('returnOriginal' in options) {
const replacement = options['returnOriginal'] ? '\'before\'' : '\'after\'';
utils.warn(
'mongoose: the `returnOriginal` option for `findOneAndUpdate()` and `findOneAndReplace()` is deprecated. ' +
'Use `returnDocument: ' + replacement + '` instead.'
);
options.returnDocument = options['returnOriginal'] ? 'before' : 'after';
delete options['returnOriginal'];
}
// Temporary since driver 4.0.0-beta does not support `returnDocument`
if (typeof options.returnDocument === 'string') {
options.returnOriginal = options.returnDocument === 'before';View on GitHub (pinned to 49cdab0136)
When it happens
Trigger: Thrown at lib/query.js:3995 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of Automattic/mongoose@49cdab0136 (2026-08-21).
Data as JSON: /api/errors/beb5650fbb7a2148.
Report an issue: GitHub.