Merging of discrimintor schema "_indexes" duplicates when both 'from' and 'to' are schema instances #14586
Closed
2 tasks done
Labels
needs repro script
Maybe a bug, but no repro script. The issue reporter should create a script that demos the issue
Prerequisites
Mongoose version
8.3.4
Node.js version
18.2
MongoDB server version
6
Typescript version (if applicable)
5.4.5
Description
When merging a discriminator schema, when both source and target are
Schema
instances the following logic is applied:from
) is clonedto
)mongoose/lib/helpers/discriminator/mergeDiscriminatorSchema.js
Line 64 in 3526799
Step 1 (clone) will also close the
_indexes
property of theSchema
creating new copied for the array and the index definitions.mongoose/lib/helpers/clone.js
Lines 175 to 184 in 3526799
Next, the merge operation will concat the
_indexes
from source and target effectivly duplicating the_indexes
on every clone.mongoose/lib/helpers/schema/merge.js
Line 34 in 3526799
For multiple discriminators and nested schema's this can lead to memory leak/overflow and other mongo implications.
Expected Behavior
when merging discriminator schemas, the clone phase should be able to optionally ignore
_indexes
cloning and the "merge" itself should clone and concat properlyThe text was updated successfully, but these errors were encountered: