You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have searched existing issues to ensure the bug has not already been reported
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.
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:
lcrosetto
changed the title
Model.updateOne() fails to update embedded fields when overwriting discriminator key
Model.updateOne() and arrayFilters fails to update embedded document array fields when overwriting embedded discriminator key
Nov 20, 2024
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: