Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(document): validateUpdatedOnly option. only validates modified #7492

Merged
merged 1 commit into from Feb 14, 2019

Conversation

captaincaius
Copy link
Contributor

@captaincaius captaincaius commented Feb 6, 2019

schema option that can be overridden on validate, validateSync, and save

Summary

#7421 - ignore validation on unmodified paths

Abandoned yucky post-filtering approach in #7483.

Examples

see tests ;)

schema option that can be overridden on validate, validateSync, and save
@captaincaius
Copy link
Contributor Author

FYI for some reason I didn't see the problem I had with the hooks the first time I tried it "the right way". I probably just had a mistake, but if anything pops into your head that I should check, LMK.

@captaincaius
Copy link
Contributor Author

Cool beans. Is there anything else you'd like done differently or added? Any other tests perhaps?

@vkarpov15 vkarpov15 changed the base branch from master to 5.5 February 14, 2019 17:24
Copy link
Collaborator

@vkarpov15 vkarpov15 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope this looks solid enough to merge into the 5.5 branch. Since this is a new feature, it'll be released with 5.5.0 sometime in March 2019.

@vkarpov15 vkarpov15 merged commit 12fe73a into Automattic:5.5 Feb 14, 2019
@exentrich
Copy link

exentrich commented Aug 19, 2019

Unfortunately this option doesn't work. And I can't find documentation for this feature.

I have this schema and options:

const Schema = mongoose.Schema({
  title: String,
  coverId: Number
}, {
  validateModifiedOnly: true
}
//pre('validate'...
this.isModified('coverId') //false
this.coverId //NaN
this.isModified('title') //true

When I try to update existing document title field, it fails because coverId field value is NaN (invalid). My use-case to ignore such validations.

Can you please help? Maybe I do something wrong.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants