Converts Zod object schemas into MongoDB validation schemas (JSON Schema compatible). Version 3.0.2 targets Node.js >=24.10 and npm >=11, with experimental Yarn support dropped. Requires Zod ^3.25.64 or ^4.0.0 and BSON ^7.0.0 as peer dependencies. Validates Zod object() schemas only; other Zod types are not supported. Ships TypeScript types. Notable breaking change in v3: switched from CJS to ESM-only, requiring dynamic import or native ESM.
npm install zod-mongodb-schemaNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Converts a Zod object schema into a MongoDB $jsonSchema validation object.
Replace require('zod-mongodb-schema') with await import('zod-mongodb-schema') or set type: module in package.json.Upgrade Node.js to 24.10+ and npm to 11+.
Wrap standalone types in z.object({ key: type }).Install zod@^3.25.64 or zod@^4.0.0.
Use import { zodMongoSchema } from 'zod-mongodb-schema' or dynamic import().Wrap the schema in z.object({ ... }).Run npm install zod@^3.25.64 bson@^7.0.0
Use z.object({ ... }) to create the schema.