{"repo":"udohjeremiah/zod-mongo-schema","free":true,"listed":false,"github":"https://github.com/udohjeremiah/zod-mongo-schema","clone":"git clone https://github.com/udohjeremiah/zod-mongo-schema.git","description":"Convert Zod schemas to MongoDB-compatible JSON Schemas effortlessly.","language":"TypeScript","stars":13,"topics":["convert","database","json","mongodb","schema","typescript","zod","annotation","validation"],"license":"MIT","category":"databases-storage","readme_excerpt":"zod-mongo-schema Convert Zod schemas to MongoDB-compatible JSON Schemas effortlessly. Overview As your project matures, the structure of your database tends to stabilize. That's where JSON Schemas come in — they let you annotate and validate your MongoDB documents so that invalid values don't sneak in and break your app in production. But writing JSON Schemas by hand isn't fun. As a JavaScript developer, chances are you're already using Zod to define your schemas. Wouldn't it be great if you could just take your existing Zod schema and instantly turn it into a MongoDB-compatible JSON Schema? That's exactly what zod-mongo-schema does. It takes your Zod schema and converts it into a ready-to-use JSON Schema that can be applied directly to your MongoDB collections for validation. Installation Note: This library expects Zod ^3.25.0 or 4.x.x as a peer dependency. Usage A basic example A nested Zod schema Specifying BSON types with .meta() If there's no direct Zod API for a BSON type, you can use z.unknown().meta() : z.date() is automatically mapped to { bsonType: \"date\" } in both strict and non-strict modes, since the mapping is unambiguous. For other BSON types without a direct Zod equivalent, in strict mode (the default) only z.unknown() can be used with .meta() to specify BSON types. Using .meta({ bsonType }) on other Zod types will throw: In non-strict mode, bsonType can be used on any Zod type. Order of .meta() with chained methods When chaining methods like .and() , .or() , ","default_branch":null,"files":null,"tree":[],"storefront":"/r/udohjeremiah","claimed":false,"request_supported":{"post":"https://gitbuyer.com/r/udohjeremiah/zod-mongo-schema/request-supported","requests":0},"note":"indexed from public GitHub; nothing is for sale on this page. Clone it from GitHub. Paid listings live at /search."}