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.14.0
Node.js version
22.13.1
MongoDB server version
"mongodb-memory-server": "^10.1.4"
Typescript version (if applicable)
5.8.2
Description
I'm attempting to migrate a time field stored as a primitive string (e.g., "12:34") to a subdocument with hours and minutes keys. This transformation needs to apply to multiple fields in a dynamic, reusable way. So there cant be a getter or init hook on the main document.
I tried two approaches:
Using a get function on the schema field.
Adding a pre("init") hook within the subdocument schema.
However, neither strategy correctly transforms the old string value. It seems the validator strips the string before the getter or hook is executed.
Prerequisites
Mongoose version
8.14.0
Node.js version
22.13.1
MongoDB server version
"mongodb-memory-server": "^10.1.4"
Typescript version (if applicable)
5.8.2
Description
I'm attempting to migrate a time field stored as a primitive string (e.g.,
"12:34"
) to a subdocument withhours
andminutes
keys. This transformation needs to apply to multiple fields in a dynamic, reusable way. So there cant be agetter
orinit
hook on the main document.I tried two approaches:
Using a
get
function on the schema field.Adding a
pre("init")
hook within the subdocument schema.However, neither strategy correctly transforms the old string value. It seems the validator strips the string before the getter or hook is executed.
Steps to Reproduce
timeSchema
and attempt to transform the string value using a getter or pre("init") hook.The string value is stripped by the validators before it can be picked up by
getter
orinit
hook.Expected Behavior
I expected previously stored string values like "12:34" to be converted into { hours: 12, minutes: 34 } and not be stripped by validations.
Expected output:
The text was updated successfully, but these errors were encountered: