File tree 1 file changed +26
-1
lines changed
1 file changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -102,7 +102,32 @@ MongooseError.CastError = require('./cast');
102
102
MongooseError . ValidationError = require ( './validation' ) ;
103
103
104
104
/**
105
- * A `ValidationError` has a hash of `errors` that contain individual `ValidatorError` instances
105
+ * A `ValidationError` has a hash of `errors` that contain individual
106
+ * `ValidatorError` instances.
107
+ *
108
+ * ####Example:
109
+ *
110
+ * const schema = Schema({ name: { type: String, required: true } });
111
+ * const Model = mongoose.model('Test', schema);
112
+ * const doc = new Model({});
113
+ *
114
+ * // Top-level error is a ValidationError, **not** a ValidatorError
115
+ * const err = doc.validateSync();
116
+ * err instanceof mongoose.Error.ValidationError; // true
117
+ *
118
+ * // A ValidationError `err` has 0 or more ValidatorErrors keyed by the
119
+ * // path in the `err.errors` property.
120
+ * err.errors['name'] instanceof mongoose.Error.ValidatorError;
121
+ *
122
+ * err.errors['name'].kind; // 'required'
123
+ * err.errors['name'].path; // 'name'
124
+ * err.errors['name'].value; // undefined
125
+ *
126
+ * Instances of `ValidatorError` have the following properties:
127
+ *
128
+ * - `kind`: The validator's `type`, like `'required'` or `'regexp'`
129
+ * - `path`: The path that failed validation
130
+ * - `value`: The value that failed validation
106
131
*
107
132
* @api public
108
133
* @memberOf Error
You can’t perform that action at this time.
0 commit comments