mongo-sanity
is a library designed to validate MongoDB documents against a predefined schema. It ensures that the documents stored in your MongoDB collections adhere to the specified structure and constraints.
- Schema Validation: Validate MongoDB documents against a predefined schema.
- Custom Validators: Define custom validation rules for specific fields.
- Error Reporting: Detailed error messages for validation failures.
- Flexible Schema Definitions: Support for various data types and nested schemas.
To install the library, use npm or yarn:
npm install mongo-sanity
import mongoose from 'mongoose';
import { connectToDatabaseAndValidateData } from 'mongo-sanity';
// Model initialization
await connectToDatabaseAndValidateData(mongoose);