Skip to main content

not

$not

Inverts a processor result - returns true if the wrapped processor throws or returns a falsey value. Throw a constraint error if the wrapped processor returns a truthy value.

This is useful for expressing negative constraints (e.g., "must not be a hostname").

See $never to require the processor returns undefined or throws an exception.

Parameters

  • value (ProcessorSpec, required): The processor specification to negate.

Example

// Reject anything that looks like an IP address (accept hostnames only)
new Schema('string').validator({$not: '$ipv4'})

// Ensure a string is not a reserved word
new Schema('string').validator({$not: {$in: ['admin', 'root', 'system']}})

// Require a URL that is NOT an HTTP URL (i.e., must be HTTPS or another scheme)
new Schema('string').validator({$not: '$http-url'}).validator('$url')