mondel
v0.3.1
Published
Lightweight TypeScript ORM for MongoDB - Type-safe, serverless-optimized
Maintainers
Readme
Overview
Mondel is a thin, type-safe ODM for MongoDB: schema definition, typed collection access (db.users), Zod validation on writes, and a CLI for indexes/validators. Filters and operators stay native MongoDB — no new query language, no document hydration magic.
Optimized for serverless (Cloudflare Workers, Vercel Edge, Lambda) and solid on long-running Node servers.
Features
- Typed collections — schema names and fields inferred with TypeScript
- Serverless-ready — factory client; no startup index sync required
- Zero magic — plain objects in/out; escape hatch via
getCollection() - Zod validation —
strict|loose|offon writes - CLI pull/push — introspect DB or apply indexes/JSON Schema in CI
- MongoDB 6–8 — works with current server and driver majors
Installation
npm install mondel mongodb zodRequirements
| | |
| --- | --- |
| Node.js | 18+ (20+ recommended with mongodb@7) |
| MongoDB | 6.0 – 8.x |
| Peers | mongodb ^6 || ^7, zod ^3.24 || ^4 |
Quick Start
import { defineSchema, s, createClient, type SchemasToClient } from "mondel";
export const userSchema = defineSchema("users", {
timestamps: true,
fields: {
email: s.string().required().email().unique(),
name: s.string(),
role: s.enum(["ADMIN", "USER"]).default("USER"),
},
});
export const schemas = [userSchema] as const;
export type DbClient = SchemasToClient<typeof schemas>;
const connect = createClient({
serverless: true,
schemas,
validation: "strict",
});
export async function getDb(uri: string): Promise<DbClient> {
return connect(uri);
}
// Usage
const db = await getDb(process.env.MONGODB_URI!);
await db.users.create({ email: "[email protected]", name: "Ada" });
const user = await db.users.findOne({ email: "[email protected]" });
await db.close();Push indexes in deploy/CI (not on cold start):
npx mondel push --uri "$MONGODB_URI" --schema ./dist/schemas.js --apply-validatorsCollection API
| Method | Notes |
| ------ | ----- |
| findOne / findMany / findById | Native filters; select = runtime projection |
| create / createMany | Defaults applied when validation on |
| updateOne / updateMany / updateById | Plain objects → $set; validates $set |
| findOneAndUpdate | Atomic find + update |
| bulkWrite | Native bulk (not re-validated) |
| deleteOne / deleteMany / deleteById | { soft: true } sets deletedAt |
| count / exists / aggregate | |
| getCollection() | Full driver access |
Documentation
Full site: https://mondel-orm.pages.dev
| | | | --- | --- | | Concepts | guide/concepts | | Compatibility | guide/compatibility | | Upgrade 0.2 → 0.3 | guide/upgrade-0.2-to-0.3 | | Comparison | guide/comparison | | CLI | guide/cli | | AI agents | llms.txt · full text | | Changelog | CHANGELOG.md |
What Mondel is not
- Not Mongoose (no middleware / virtuals / populate)
- Not Prisma (no relation engine or full data migrations)
- Not a replacement for learning MongoDB query operators
Contributing
See CONTRIBUTING.md.
License
MIT © Edjo
