I have a mongodb schema like below.
const DemoSchema: Schema = new Schema({
demoProperty1: { type: String, required: true }
});
I create a document with syntax in node js server like below.
const savedDemo = await this.demoModel.create({demoProperty1:""});
Why it is returning error message
UnhandledPromiseRejectionWarning: ValidationError:
How to fix this issue?
2
Answers
Yes I have fix this issue by trial and error. Empty string is not eligible for mongodb required schema, Took me 5 hours to figure it out. I can just passed in any string but not an empty string to make it valid and passed without any error.
From the documentation: