Skip validation for certain path(s) in Document.validate() method
See original GitHub issueDo you want to request a feature or report a bug?
Bug
What is the current behavior?
Unable to skip or prevalidate or bypass the validation for a path on mongoose
If the current behavior is a bug, please provide the steps to reproduce.
- Create a model
- Add required validator on a path
- Run the doc.$markValid(“path”)
- Try
doc.validate(["path"]).catch(e => console.log(Object.keys(e.errors).length))
- The length would be == 1
Here I want to bypass the required
validation for gwId field
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"outDir": "./dist",
"strict": true,
"noImplicitAny": true,
"typeRoots": ["./ctypings", "./node_modules/@types"],
"types": ["express", "express-session", "process", "express-request-id"],
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true
},
"exclude": ["node_modules", "./node_modules", "./node_modules/*", "./node_modules/@types/node/index.d.ts"],
"include": ["src/**/*.ts", "ctypings/**/*.ts"]
}
What is the expected behaviour?
Well, $markValid should bypass all the validators for one or more paths (except unique)
What are the versions of Node.js, Mongoose and MongoDB you are using? Note that “latest” is not a version.
Mongoose: 5.12.7
Node: v14.16.0
Mongodb: 3.6.6
Issue Analytics
- State:
- Created 2 years ago
- Comments:14 (6 by maintainers)
Top Results From Across the Web
jQuery Validation plugin: disable validation for specified ...
Hello @lepe, you know how to re-apply jquery validation after writing $("form").validate().cancelSubmit = true; . I tried $("form").validate().cancelSubmit = ...
Read more >48817 – Skip validation query and use JDBC API for validation
I've added a Validator interface with the following single method: public boolean validate(Connection connection, int validateAction) I also ...
Read more >Mongoose v6.8.2: Validation
Before running validators, Mongoose attempts to coerce values to the correct type. This process is called casting the document. If casting fails for...
Read more >Active Record Validations - Ruby on Rails Guides
The following methods skip validations, and will save the object to the database regardless of its validity. They should be used with caution....
Read more >Client-side form validation - Learn web development | MDN
One of the most significant features of modern form controls is the ability to validate most user data without relying on JavaScript. This...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’m currently working on a series of blog posts about that very subject 😃 First one is here: http://thecodebarbarian.com/mongoose-internals-schemas-options-models.html .
Re: sanitizing query filters, we’re working on that for Mongoose 6.0. Follow #3944 for updates.