Define Mongoose schemas with Zod.
Create Mongoose schemas from Zod objects. Start with a model you can validate in memory, then use the guides when you need nested objects, references, or shared schemas.
example.ts
import { z } from 'zod/v4'; import { toMongooseSchema } from '@nullix/zod-mongoose'; import type { InferDocument } from '@nullix/zod-mongoose'; const UserZodSchema = z.object({ username: z.string().min(3), email: z.string().email(), }); const UserSchema = toMongooseSchema(UserZodSchema); // The stored document type includes Mongoose's generated _id. type User = InferDocument<typeof UserZodSchema>;
What do you need to do?
Ready to build a model?
Follow a small example from installation to validation, then connect to MongoDB when you need to save.
:::