Document.prototype.validate()

Parameters
  • [pathsToValidate] «Array|String» list of paths to validate. If set, Mongoose will validate only the modified paths that are in the given list.

  • [options] «Object» internal options

  • [options.validateModifiedOnly=false] «Boolean» if true mongoose validates only modified paths.

  • [callback] «Function» optional callback called after validation completes, passing an error if one occurred

Returns:
  • «Promise» Promise

Executes registered validation rules for this document.

Note:

This method is called pre save and if a validation rule is violated, save is aborted and the error is returned to your callback.

Example:

  1. doc.validate(function (err) {
  2. if (err) handleError(err);
  3. else // validation passed
  4. });