-
Hello, i have existing system with messy and barely defined schemas with mongoose. I tried to migrate one to typegoose - Users. Put explicit field types, added missing fields (that were in db but not defined in mongoose schemas). Everything is fine. Everything worked fine, till one case in prod, where user cant update anything. When trying to update email, it says that name is required. And in typegoose scheme name is marked as required (it was in mongoose definition as well). But in db it is empty. (I believe reason is because all places that uses mongoose does not work with instances but update everything with So code Is there better way how to allow to save email, but not trigger unrelated field validations? Or am i doomed? Its bad that we have such messy data, but it is what it its and we will clean them up over time, but for now, we are sort of stuck in this limbo, where we cannot reliably migrate to typegoose because of those validation errors. I understand reasoning to validate entity completeness, but for our use case it would be so great to validate only fields that actually has been changed. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
I ubderstand that this issue is more related to mongoose it self and typegoose is just a wrapper. |
Beta Was this translation helpful? Give feedback.
-
this is to be expected, mongoose by default validates all paths on
|
Beta Was this translation helpful? Give feedback.
this is to be expected, mongoose by default validates all paths on
.save
, this can be changed with optionvalidateModifiedOnly: true
updateOne
supports to run validators on that path, but it is disabled by default, it can be enabled with optionrunValidators: true