···1# **Nozzle**
23-A lightweight, type-safe ODM for MongoDB in TypeScript — inspired by
4-[Drizzle ORM](https://orm.drizzle.team/) and built for developers who value
5-simplicity, transparency, and strong typings.
67-> **Note:** Nozzle DB requires MongoDB **4.2 or newer** and works best with the
8> latest stable MongoDB server (6.x or newer) and the official
9> [mongodb](https://www.npmjs.com/package/mongodb) Node.js driver (v6+).
1011## ✨ Features
1213-- **Schema-first:** Define and validate collections using
14- [Zod](https://zod.dev/).
15- **Type-safe operations:** Auto-complete and strict typings for `insert`,
16 `find`, `update`, and `delete`.
17- **Minimal & modular:** No decorators or magic. Just clean, composable APIs.
18-- **Developer-friendly DX:** Great TypeScript support and IDE integration.
19- **Built on MongoDB native driver:** Zero overhead with full control.
2021---
···3334## 🚀 Quick Start
3500036### 1. Define a schema
3738```ts
39// src/schemas/user.ts
40import { z } from "zod";
41-import { defineModel } from "@nozzle/nozzle";
4243export const userSchema = z.object({
44 name: z.string(),
···61 disconnect,
62 InferModel,
63 InsertType,
64- MongoModel,
65} from "@nozzle/nozzle";
66import { userSchema } from "./schemas/user";
67import { ObjectId } from "mongodb"; // v6+ driver recommended
···72async function main() {
73 // Use the latest connection string format and options
74 await connect("mongodb://localhost:27017", "your_database_name");
75- const UserModel = new MongoModel("users", userSchema);
7677 // Your operations go here
78
···1# **Nozzle**
23+A lightweight, type-safe ODM for MongoDB in TypeScript
0045+> **Note:** Nozzle requires MongoDB **4.2 or newer** and works best with the
6> latest stable MongoDB server (6.x or newer) and the official
7> [mongodb](https://www.npmjs.com/package/mongodb) Node.js driver (v6+).
89## ✨ Features
1011+- **Schema-first:** Define and validate collections using any schema validator
12+ that supports [Standard Schema](https://standardschema.dev).
13- **Type-safe operations:** Auto-complete and strict typings for `insert`,
14 `find`, `update`, and `delete`.
15- **Minimal & modular:** No decorators or magic. Just clean, composable APIs.
016- **Built on MongoDB native driver:** Zero overhead with full control.
1718---
···3031## 🚀 Quick Start
3233+Examples below use Zod but any schema validator that supports
34+[Standard Schema](https://standardschema.dev) will work.
35+36### 1. Define a schema
3738```ts
39// src/schemas/user.ts
40import { z } from "zod";
04142export const userSchema = z.object({
43 name: z.string(),
···60 disconnect,
61 InferModel,
62 InsertType,
63+ Model,
64} from "@nozzle/nozzle";
65import { userSchema } from "./schemas/user";
66import { ObjectId } from "mongodb"; // v6+ driver recommended
···71async function main() {
72 // Use the latest connection string format and options
73 await connect("mongodb://localhost:27017", "your_database_name");
74+ const UserModel = new Model("users", userSchema);
7576 // Your operations go here
77
···1import type { StandardSchemaV1 } from "@standard-schema/spec";
2import type { ObjectId } from "mongodb";
34-export type InferModel<
5- T extends StandardSchemaV1<unknown, Record<string, unknown>>,
6-> =
7- & StandardSchemaV1.InferOutput<T>
8- & {
9- _id?: ObjectId;
10- };
1112-export type InsertType<
13- T extends StandardSchemaV1<unknown, Record<string, unknown>>,
14-> =
15- & Omit<StandardSchemaV1.InferOutput<T>, "createdAt">
16- & { createdAt?: Date };
···1import type { StandardSchemaV1 } from "@standard-schema/spec";
2import type { ObjectId } from "mongodb";
34+type Schema = StandardSchemaV1<unknown, Record<string, unknown>>;
5+type Infer<T extends Schema> = StandardSchemaV1.InferOutput<T>;
6+7+export type InferModel<T extends Schema> = Infer<T> & {
8+ _id?: ObjectId;
9+};
01011+export type InsertType<T extends Schema> = Omit<Infer<T>, "createdAt"> & {
12+ createdAt?: Date;
13+};
00
+1-1
tests/main_test.ts
···1import { assertEquals, assertExists, assertRejects } from "jsr:@std/assert";
2-import { z } from "zod";
3import { connect, disconnect, type InsertType, Model } from "../mod.ts";
4import { ObjectId } from "mongodb";
5
···1import { assertEquals, assertExists, assertRejects } from "jsr:@std/assert";
2+import { z } from "jsr:@zod/zod";
3import { connect, disconnect, type InsertType, Model } from "../mod.ts";
4import { ObjectId } from "mongodb";
5
+1-1
tests/mock_test.ts
···1import { afterEach, beforeEach, describe, it } from "jsr:@std/testing/bdd";
2import { assertEquals, assertExists, assertRejects } from "jsr:@std/assert";
3-import { z } from "zod";
45// Mock implementation for demonstration
6class MockModel<T> {
···1import { afterEach, beforeEach, describe, it } from "jsr:@std/testing/bdd";
2import { assertEquals, assertExists, assertRejects } from "jsr:@std/assert";
3+import { z } from "jsr:@zod/zod";
45// Mock implementation for demonstration
6class MockModel<T> {