Schema Validation API
Collection-level document verification capabilities ensure data quality.
setValidator()
Set Schema validation rules for a collection.
Syntax
Parameters
- validator (Object, required): Validation rules
- options (Object, optional):
validationLevel(string): Authentication levelvalidationAction(string): Verification behavior
Validation rule format
1. JSON Schema (recommended)
2. Query expression
Example
setValidationLevel()
Set the verification level.
Verification level
strict: Validate all inserts and updates (default)moderate: Only valid updates to valid documents are verified, existing invalid documents are not verifiedoff: Disable verification
Syntax (setValidationLevel())
Example (setValidationLevel())
setValidationAction()
Set the behavior when validation fails.
Verify behavior
error: Reject documents that do not comply with the rules (default)warn: Allow writing but log warning
Syntax (setValidationAction())
Example (setValidationAction())
getValidator()
Get the current authentication configuration.
Syntax (getValidator())
Return value
- Type:
Promise<Object> - Properties:
validator(Object|null): Validation rulesvalidationLevel(string): Authentication levelvalidationAction(string): Verification behavior
Example (getValidator())
Complete example
Related documents
- Collection Management - collMod, stats
- Collection Management Example