{
"data": [
{
"_id": "581c8c0e8ae4dbf68e92e178",
"name": "Batman",
"ocupation": "CEO of Wayne Enterprises",
"quote": "As a symbol I can be incorruptible. I can be everlasting.",
"__v": 0,
"firstAppearance": 1939
},
{
"_id": "581cb70702eec407ff7414dd",
"name": "Joker",
"ocupation": "Villain",
"quote": "Why so serious?",
"__v": 0,
"firstAppearance": 1940
}
]
}
Mongoose Validation Errors
How to create custom errors with mongoose
charactersModel.js
const minFirstAppearance = [1939, 'The first appearance year should be greater than 1939'];
const charactersSchema = mongoSchema({
firstAppearance: { type: Number, min: minFirstAppearance, default: 1939}
});
{
"error": {
"type": "ValidationError",
"message": "characters validation failed",
"description": {
"firstAppearance": "The first appearance year should be greater than 1939"
}
}
}