🛡️
Zod Validation
Automatic schema validation on inserts and updates. Catch errors before they hit your database.
Type-safe, lightweight MongoDB ODM with automatic validation, serialization, and full TypeScript support.
import { collection, field } from '@codician-team/monch';
// Define your collection with Zod schema
const Users = collection({
name: 'users',
schema: {
_id: field.id(),
name: field.string().min(1),
email: field.email(),
role: field.enum(['user', 'admin']).default('user'),
},
timestamps: true,
});
// Insert with automatic validation
const user = await Users.insertOne({
name: 'Alice',
email: 'alice@example.com',
});
// Query with type-safe results
const admins = await Users.find({ role: 'admin' }).toArray();
// Serialize for Next.js Client Components
const serialized = user.serialize();
// { _id: '507f1f77...', name: 'Alice', email: '...', createdAt: '2024-01-15T...' }