Document.prototype.invalidate()

Parameters
  • path «String» the field to invalidate. For array elements, use the array.i.field syntax, where i is the 0-based index in the array.

  • errorMsg «String|Error» the error which states the reason path was invalid

  • value «Object|String|Number|any» optional invalid value

  • [kind] «String» optional kind property for the error

Returns:
  • «ValidationError» the current ValidationError, with all currently invalidated paths

Marks a path as invalid, causing validation to fail.

The errorMsg argument will become the message of the ValidationError.

The value argument (if passed) will be available through the ValidationError.value property.

  1. doc.invalidate('size', 'must be less than 20', 14);
  2. doc.validate(function (err) {
  3. console.log(err)
  4. // prints
  5. { message: 'Validation failed',
  6. name: 'ValidationError',
  7. errors:
  8. { size:
  9. { message: 'must be less than 20',
  10. name: 'ValidatorError',
  11. path: 'size',
  12. type: 'user defined',
  13. value: 14 } } }
  14. })