Model.updateOne() and arrayFilters fails to update embedded document array fields when overwriting embedded discriminator key #15051
Labels
confirmed-bug
We've confirmed this is a bug in Mongoose and will fix it.
Milestone
Prerequisites
Mongoose version
8.8.2
Node.js version
20.18.0
MongoDB server version
8.0.1
Typescript version (if applicable)
No response
Description
When using
Model.updateOne()
and arrayFilters to overwrite the discriminator key in an embedded document array with schema discriminators (and setting the overwriteDiscriminatorKey option), the discriminator key is updated, but fields unique to the discriminator schema fail to be updated. I suspect this is a problem with determining the schema from the update object, possibly related to the getEmbeddedDiscriminatorPath() helper.Steps to Reproduce
The following script will fail to update field2:
Expected Behavior
Model.updateOne()
should update the fields from the discriminator (key) set in the update, if overwriteDiscriminatorKey is set to true. Probably the schema would be found using the discriminator key in the update:'testArray.$[element].key': 'Type2',
The text was updated successfully, but these errors were encountered: