Registry / database / mondel

mondel

JSON →
library0.2.4jsnpmunverified

Mondel is a lightweight TypeScript ORM for MongoDB, optimized for serverless environments (Cloudflare Workers, Vercel Edge, AWS Lambda). Current stable version is 0.2.4. It provides 100% type-safe schemas with full inference, Zod integration for runtime validation, and a Prisma/Drizzle-inspired API. Unlike Mongoose or Typegoose, it uses zero decorators or reflection, resulting in a minimal bundle (~27KB) and no cold-start overhead. It requires Node.js 18+, MongoDB 6.0+, and TypeScript 5.0+.

npm install mondel
INSTALL
IMPORT
SIG · MONDEL
M
mondel
databasejavascriptv0.2.4
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

defineSchema
import { defineSchema } from 'mondel'
const defineSchema = require('mondel').defineSchema
ESM-only since v0.1.0
createClient
import { createClient } from 'mondel'
import { createClient } from 'mondel/client'
Main export path; no subpath exports
SchemasToClient
import type { SchemasToClient } from 'mondel'
import { SchemasToClient } from 'mondel'
TypeScript type, import as type
s
import { s } from 'mondel'
import { s } from 'mondel/schema'
Utility object for defining field types

Complete example: define schema, create serverless client, perform CRUD, close connection.

import { defineSchema, createClient, s, type SchemasToClient } from 'mondel'; const userSchema = defineSchema('users', { timestamps: true, fields: { email: s.string().required().unique().index({ name: 'idx_email' }), name: s.string(), role: s.enum(['ADMIN', 'USER', 'GUEST']).default('USER'), age: s.number().min(0).max(150), isActive: s.boolean().default(true), }, }); const schemas = [userSchema] as const; type DbClient = SchemasToClient<typeof schemas>; const connectDb = createClient({ serverless: true, schemas, validation: 'strict', }); export async function getDb(uri: string): Promise<DbClient> { return connectDb(uri); } async function main() { const db = await getDb(process.env.MONGODB_URI ?? ''); await db.users.create({ email: 'john@example.com', name: 'John Doe', role: 'USER' }); const user = await db.users.findOne({ email: 'john@example.com' }, { select: { _id: true, email: true } }); console.log(user); await db.close(); } main().catch(console.error);
Debug
Known issues
breakingv0.1.0 changed import paths: all exports now from 'mondel' main entry; subpath imports removed.
fix
Use import { defineSchema, createClient, s } from 'mondel' instead of from 'mondel/schema' etc.
affects: >=0.1.0
gotchaserverless: true in createClient requires calling connectDb per request; connection is not persistent.
fix
For persistent connections in non-serverless env, set serverless: false or omit.
affects: >=0.2.0
deprecateduse of s.enum() with string array is deprecated in favor of const assertions since v0.2.0.
fix
Use s.enum(['A', 'B'] as const) or define a const enum.
affects: >=0.2.0
gotchaTypeScript error when using .findOne() without filter: filter is required, unlike MongoDB driver.
fix
Always pass a filter object; use {} to match all.
affects: >=0.1.0
breakingv0.2.0 renamed 'collection' property in defineSchema to 'name' and changed field type builder signature.
fix
Use 'name' instead of 'collection'; update field definitions to new builder pattern.
affects: >=0.2.0
Errors
Common errors & fixes
Property 'rooms' does not exist on type 'DbClient'
Accessing a schema that hasn't been registered in createClient
fix
Ensure you pass all schema definitions in the 'schemas' array to createClient and that the type includes them.
MongoServerError: E11000 duplicate key error collection: test.users index: idx_email dup key
Attempting to insert a document with an email that already exists
fix
Use .updateOne with upsert: true or check existence first.
TypeError: Cannot destructure property 'connectDb' of undefined
Missing peer dependencies (mongodb or zod) in node_modules
fix
Run npm install mongodb zod since they are peer dependencies.
Expected 1-2 arguments, but got 0.
Calling .findOne() without filter parameter
fix
Provide at least an empty filter object: db.users.findOne({}, { select: { name: true } })
Upgrade
Version history
0.2.4latest on npm
Audit
Dependencies
mongodbrequiredPeer dependency for MongoDB driver (^6.0.0 || ^7.0.0)
zodrequiredPeer dependency for runtime schema validation (^3.24.0 || ^4.0.0)
Agent activity
2 hits · last 30 days
node
2
Resources
packagemondel
mondel — npm install mondel · libregistry