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
Do you want to request a feature or report a bug?
Bug or extension of current feature?
What is the current behavior?
Updating a nested discriminator by dot notation drops any attributes not defined in base schema even if discriminator key is provided in the update.
If the current behavior is a bug, please provide the steps to reproduce.
What is the expected behavior?
The update will cast, (validate when runValidators=true) and update 'shape.kind' and 'shape.name' but drops 'shape.radius' which is defined in the discriminator schema. When updates use dot notation and path is a nested (or array) discriminator then should use discriminator key provided in the updates (or fallback to existing doc discriminatorKey value?) for correct casting. Currently the only way to set 'shape.radius' is to set strict=false (which defeats the purpose of defining a schema) or first retrieve the doc, apply the partial updates and .save(). Atomic operations are required.
What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
Node.js 10.16.3
Mongoose 5.7.12
MongoDB 4.0.3
The text was updated successfully, but these errors were encountered:
vkarpov15
added
confirmed-bug
We've confirmed this is a bug in Mongoose and will fix it.
and removed
has repro script
There is a repro script, the Mongoose devs need to confirm that it reproduces the issue
labels
Dec 5, 2019
Do you want to request a feature or report a bug?
Bug or extension of current feature?
What is the current behavior?
Updating a nested discriminator by dot notation drops any attributes not defined in base schema even if discriminator key is provided in the update.
If the current behavior is a bug, please provide the steps to reproduce.
What is the expected behavior?
The update will cast, (validate when
runValidators=true
) and update 'shape.kind' and 'shape.name' but drops 'shape.radius' which is defined in the discriminator schema. When updates use dot notation and path is a nested (or array) discriminator then should use discriminator key provided in the updates (or fallback to existing doc discriminatorKey value?) for correct casting. Currently the only way to set 'shape.radius' is to setstrict=false
(which defeats the purpose of defining a schema) or first retrieve the doc, apply the partial updates and .save(). Atomic operations are required.What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
Node.js 10.16.3
Mongoose 5.7.12
MongoDB 4.0.3
The text was updated successfully, but these errors were encountered: