required: true on objectId causes the validation to fail
See original GitHub issueI have a Schema that contains a Ref to another one. If I mark it as required, to validation fails. Without this attributes, everything go fine, including the ref.
Here is the actual Schema
answerChoiceSchema = new schema {
propositionId: { type: objectId, required: true},
dispo: { type: String, required: true, enum: ['yes', 'no']}
}
and an extract of my code
//c comes directly from a POST key/value array which just fine
choice = new Choice
choice.propositionId = c.propositionId
choice.dispo = c.dispo
answer.choices.push choice
I do not know if this is of any help to find the issue but “choice” data comes at 3rd level of nesting (parent->answers->choices)
What can I do about it ?
Issue Analytics
- State:
- Created 12 years ago
- Comments:7
Top Results From Across the Web
Why do I have a fail validation with mongodb? - Stack Overflow
Okay, I got the solution, the problem was the additional rule Properties. So if it's on false, you have to add the _id...
Read more >Mongoose v6.8.2: API docs
Returns true if the given value is a Mongoose ObjectId (using instanceof ) or if the given value is a 24 character hex...
Read more >How To Use Schema Validation in MongoDB - DigitalOcean
In MongoDB, the database engine feature that makes it possible to apply constraints on the document structure is called Schema Validation ...
Read more >Failed to parse field of type in document with id ''. - Opster
This error is actually quite simple to replicate. You only need to make sure you are somehow not respecting Elasticsearch's constraints for the...
Read more >Schema Validation — MongoDB Manual
What Happens When a Document Fails Validation ... By default, when an insert or update operation would result in an invalid document, MongoDB...
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 FreeTop 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
Top GitHub Comments
I have the same problem
I think I found mistake in my code after writing short example. I was passing options to create method but it treated them as second set of argument and of course validation failed. Thank you!
In case somebody else need it, this doesn’t work:
But this works