From d9c7051ec326a532144d1c4afefd571f31eca32c Mon Sep 17 00:00:00 2001 From: Valeri Karpov Date: Tue, 24 Dec 2024 11:57:40 -0500 Subject: [PATCH 1/2] types: add cleanIndexes() to IndexManager interface --- types/indexes.d.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/types/indexes.d.ts b/types/indexes.d.ts index 87cd8a2063..bfb1bd1cbb 100644 --- a/types/indexes.d.ts +++ b/types/indexes.d.ts @@ -10,6 +10,9 @@ declare module 'mongoose' { function syncIndexes(options?: SyncIndexesOptions): Promise; interface IndexManager { + /* Deletes all indexes that aren't defined in this model's schema. Used by `syncIndexes()`. */ + cleanIndexes(options?: { toDrop?: string[], hideIndexes?: boolean }): Promise; + /** * Similar to `ensureIndexes()`, except for it uses the [`createIndex`](https://mongodb.github.io/node-mongodb-native/4.9/classes/Collection.html#createIndex) * function. From ae001e7711d1aa7b9dce7d6a254c487e051a2e82 Mon Sep 17 00:00:00 2001 From: Valeri Karpov Date: Thu, 26 Dec 2024 14:11:53 -0500 Subject: [PATCH 2/2] fix lint and address code review comments --- lib/model.js | 2 +- types/indexes.d.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/model.js b/lib/model.js index 7edbce6ce2..b50ea3b09c 100644 --- a/lib/model.js +++ b/lib/model.js @@ -3688,7 +3688,7 @@ Model.castObject = function castObject(obj, options) { } if (schemaType.$isMongooseDocumentArray) { - const castNonArraysOption = schemaType.options?.castNonArrays ??schemaType.constructor.options.castNonArrays; + const castNonArraysOption = schemaType.options?.castNonArrays ?? schemaType.constructor.options.castNonArrays; if (!Array.isArray(val)) { if (!castNonArraysOption) { if (!options.ignoreCastErrors) { diff --git a/types/indexes.d.ts b/types/indexes.d.ts index bfb1bd1cbb..884e41cae9 100644 --- a/types/indexes.d.ts +++ b/types/indexes.d.ts @@ -10,7 +10,7 @@ declare module 'mongoose' { function syncIndexes(options?: SyncIndexesOptions): Promise; interface IndexManager { - /* Deletes all indexes that aren't defined in this model's schema. Used by `syncIndexes()`. */ + /* Deletes all indexes that aren't defined in this model's schema. Used by `syncIndexes()`. Returns list of dropped index names. */ cleanIndexes(options?: { toDrop?: string[], hideIndexes?: boolean }): Promise; /**