Skip to content

migrate from mongoose to use typegoose with inconsistent data #859

Answered by hasezoey
revati asked this question in Q&A
Discussion options

You must be logged in to vote

So code newUserModel.find({_id: id}).changeEmail(newEmail).save() does not work and throws error about name not being present

this is to be expected, mongoose by default validates all paths on .save, this can be changed with option validateModifiedOnly: true

I know i could too use newUserModel.updateOne({_id: id}, {$set: {email: newEmail}}) but i don't like this approach, as it bypasses email validation

updateOne supports to run validators on that path, but it is disabled by default, it can be enabled with option runValidators: true

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@revati
Comment options

Answer selected by revati
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Qustions about how to use stuff
2 participants
Converted from issue

This discussion was converted from issue #857 on June 28, 2023 12:22.