Below is my diagram:
var userSchema = new Schema({ username: { type: String, required: true }, password: { type: String, required: false } });
Now, when I try to save the document of the above schema, I get the following error:
{ message: 'Validation failed', name: 'ValidationError', errors: { username: { message: 'Validator "required" failed for path username', name: 'ValidatorError', path: 'username', type: 'required' } } }
The above error object is returned by mongoose on save. I was looking for this error, but could not understand what was wrong. The document I'm trying to save is as follows:
{ username: "foo" password: "bar" }
Any idea what that means? I also searched mongoose docs but couldn't find anything in the validation section.
source share