Skip to content

Commit

Permalink
BREAKING CHANGE: remove support for overwrite option setting findOneA…
Browse files Browse the repository at this point in the history
…ndUpdate to findOneAndReplace

Re: #13578
  • Loading branch information
vkarpov15 committed Oct 17, 2023
1 parent f6e5a50 commit d14e94d
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 34 deletions.
19 changes: 0 additions & 19 deletions lib/query.js
Expand Up @@ -1670,15 +1670,6 @@ Query.prototype.setOptions = function(options, overwrite) {
return this;
};

/*!
* ignore
*/

const printOverwriteDeprecationWarning = util.deprecate(
function printOverwriteDeprecationWarning() {},
'The `overwrite` option for `findOneAndUpdate()` is deprecated. use `findOneAndReplace()` instead.'
);

/**
* Sets the [`explain` option](https://www.mongodb.com/docs/manual/reference/method/cursor.explain/),
* which makes this query return detailed execution stats instead of the actual
Expand Down Expand Up @@ -3259,16 +3250,6 @@ Query.prototype.findOneAndUpdate = function(filter, doc, options) {
*/

Query.prototype._findOneAndUpdate = async function _findOneAndUpdate() {
// For backwards compability with Mongoose 6 re: #13550

if (this._mongooseOptions.overwrite != null) {
printOverwriteDeprecationWarning();
}
if (this._mongooseOptions.overwrite) {
this.op = 'findOneAndReplace';
return this._findOneAndReplace();
}

this._castConditions();

_castArrayFilters(this);
Expand Down
10 changes: 0 additions & 10 deletions test/query.test.js
Expand Up @@ -4156,16 +4156,6 @@ describe('Query', function() {
/Query must have `op` before executing/
);
});
it('converts findOneAndUpdate to findOneAndReplace if overwrite set (gh-13550)', async function() {
const testSchema = new Schema({
name: { type: String }
});

const Test = db.model('Test', testSchema);
const q = Test.findOneAndUpdate({}, { name: 'bar' }, { overwrite: true });
await q.exec();
assert.equal(q.op, 'findOneAndReplace');
});

it('allows deselecting discriminator key (gh-13760) (gh-13679)', async function() {
const testSchema = new Schema({ name: String, age: Number });
Expand Down
10 changes: 5 additions & 5 deletions types/inferschematype.d.ts
Expand Up @@ -32,14 +32,14 @@ declare module 'mongoose' {
EnforcedDocType :
{
[
K in keyof (RequiredPaths<DocDefinition, TSchemaOptions['typeKey']> &
OptionalPaths<DocDefinition, TSchemaOptions['typeKey']>)
K in keyof (RequiredPaths<DocDefinition, TSchemaOptions['typeKey']> &
OptionalPaths<DocDefinition, TSchemaOptions['typeKey']>)
]: IsPathRequired<DocDefinition[K], TSchemaOptions['typeKey']> extends true ?
ObtainDocumentPathType<DocDefinition[K], TSchemaOptions['typeKey']> :
ObtainDocumentPathType<DocDefinition[K], TSchemaOptions['typeKey']> | null;
};
};

/**
/**
* @summary Obtains document schema type from Schema instance.
* @param {Schema} TSchema `typeof` a schema instance.
* @example
Expand All @@ -48,7 +48,7 @@ declare module 'mongoose' {
* // result
* type UserType = {userName?: string}
*/
export type InferSchemaType<TSchema> = IfAny<TSchema, any, ObtainSchemaGeneric<TSchema, 'DocType'>>;
export type InferSchemaType<TSchema> = IfAny<TSchema, any, ObtainSchemaGeneric<TSchema, 'DocType'>>;

/**
* @summary Obtains schema Generic type by using generic alias.
Expand Down

0 comments on commit d14e94d

Please sign in to comment.