bug: field with alias: 'id'
has conflict with schema automatic id setter
#13650
Labels
confirmed-bug
We've confirmed this is a bug in Mongoose and will fix it.
Milestone
Prerequisites
Mongoose version
7.4.0
Node.js version
16.20.0
MongoDB server version
6.0.6
Typescript version (if applicable)
No response
Description
After updating mongoose to version 7.4.0, an error appeared (everything worked correctly on version 7.3.4).
Adding to schema a field with
alias: 'id'
causes strange setter behaviour (see Steps to Reproduce). The bug is related to the commit 32a84b7Steps to Reproduce
Steps to Reproduce:
Output:
Expected Behavior
I understand that object validation fails because of the
CastError
error, and it is called because an object is passed toremoveMultipleSpaces
and aTypeError
already occurs there.I found out that there are several ways to solve the problem:
alias: 'id'
. Since version 7.4.0 added an automatic setter for theid
virtual field (commit: 32a84b7).{ id: false }
option to the schema to disable automatic addition of theid
virtual field with its getter/setterremoveMultipleSpaces
that a string came in (but this is strange because I defined the setter for a string field).Also I suggest adding a new feature to mongoose:
The text was updated successfully, but these errors were encountered: