···11# **Nozzle**
2233-A lightweight, type-safe ODM for MongoDB in TypeScript — inspired by
44-[Drizzle ORM](https://orm.drizzle.team/) and built for developers who value
55-simplicity, transparency, and strong typings.
33+A lightweight, type-safe ODM for MongoDB in TypeScript
6477-> **Note:** Nozzle DB requires MongoDB **4.2 or newer** and works best with the
55+> **Note:** Nozzle requires MongoDB **4.2 or newer** and works best with the
86> latest stable MongoDB server (6.x or newer) and the official
97> [mongodb](https://www.npmjs.com/package/mongodb) Node.js driver (v6+).
108119## ✨ Features
12101313-- **Schema-first:** Define and validate collections using
1414- [Zod](https://zod.dev/).
1111+- **Schema-first:** Define and validate collections using any schema validator
1212+ that supports [Standard Schema](https://standardschema.dev).
1513- **Type-safe operations:** Auto-complete and strict typings for `insert`,
1614 `find`, `update`, and `delete`.
1715- **Minimal & modular:** No decorators or magic. Just clean, composable APIs.
1818-- **Developer-friendly DX:** Great TypeScript support and IDE integration.
1916- **Built on MongoDB native driver:** Zero overhead with full control.
20172118---
···33303431## 🚀 Quick Start
35323333+Examples below use Zod but any schema validator that supports
3434+[Standard Schema](https://standardschema.dev) will work.
3535+3636### 1. Define a schema
37373838```ts
3939// src/schemas/user.ts
4040import { z } from "zod";
4141-import { defineModel } from "@nozzle/nozzle";
42414342export const userSchema = z.object({
4443 name: z.string(),
···6160 disconnect,
6261 InferModel,
6362 InsertType,
6464- MongoModel,
6363+ Model,
6564} from "@nozzle/nozzle";
6665import { userSchema } from "./schemas/user";
6766import { ObjectId } from "mongodb"; // v6+ driver recommended
···7271async function main() {
7372 // Use the latest connection string format and options
7473 await connect("mongodb://localhost:27017", "your_database_name");
7575- const UserModel = new MongoModel("users", userSchema);
7474+ const UserModel = new Model("users", userSchema);
76757776 // Your operations go here
7877
···11import type { StandardSchemaV1 } from "@standard-schema/spec";
22import type { ObjectId } from "mongodb";
3344-export type InferModel<
55- T extends StandardSchemaV1<unknown, Record<string, unknown>>,
66-> =
77- & StandardSchemaV1.InferOutput<T>
88- & {
99- _id?: ObjectId;
1010- };
44+type Schema = StandardSchemaV1<unknown, Record<string, unknown>>;
55+type Infer<T extends Schema> = StandardSchemaV1.InferOutput<T>;
66+77+export type InferModel<T extends Schema> = Infer<T> & {
88+ _id?: ObjectId;
99+};
11101212-export type InsertType<
1313- T extends StandardSchemaV1<unknown, Record<string, unknown>>,
1414-> =
1515- & Omit<StandardSchemaV1.InferOutput<T>, "createdAt">
1616- & { createdAt?: Date };
1111+export type InsertType<T extends Schema> = Omit<Infer<T>, "createdAt"> & {
1212+ createdAt?: Date;
1313+};
+1-1
tests/main_test.ts
···11import { assertEquals, assertExists, assertRejects } from "jsr:@std/assert";
22-import { z } from "zod";
22+import { z } from "jsr:@zod/zod";
33import { connect, disconnect, type InsertType, Model } from "../mod.ts";
44import { ObjectId } from "mongodb";
55
+1-1
tests/mock_test.ts
···11import { afterEach, beforeEach, describe, it } from "jsr:@std/testing/bdd";
22import { assertEquals, assertExists, assertRejects } from "jsr:@std/assert";
33-import { z } from "zod";
33+import { z } from "jsr:@zod/zod";
4455// Mock implementation for demonstration
66class MockModel<T> {