Skip to main content

defined

$defined

Allow any value, as long as it's defined.

Example

// Ensure an optional field, when supplied, is not undefined
new Schema('any').validator('$defined')

// Gate a sub-pipeline: only run if the value is defined
new Schema('any').normalizer({$gate: ['$defined', '$trim']})

// Require a computed result to be defined
new Schema('string').validator({$require: {$get: {path: 'nested.key'}}})