Been struggling with MongoDB ORMs in serverless environments for months. Everything was either too heavy, had terrible TypeScript support, or just didn’t work with Cloudflare Workers’ connection model.
Just wanted to share what I ended up building - Mondel. It’s a 27KB TypeScript ORM that actually solves the serverless MongoDB problems:
const userSchema = defineSchema("users", {
timestamps: true,
fields: {
email: s.string().required().unique(),
role: s.enum(["ADMIN", "USER"]).default("USER"),
},
});
// Factory pattern for serverless (no persistent connections)
const connect = createClient({ serverless: true, schemas });
// Just works in Workers
const db = await connect(env.MONGODB_URI);
const user = await db.users.create({ email: "test@example.com" });
What finally worked for me:
-
Bundle size under 30KB (was hitting 100KB+ with other ORMs)
-
Full TypeScript autocomplete (no more runtime type errors)
-
Lazy connections (crucial for Workers pricing model)
-
Built-in Zod validation
-
Transactions, aggregations - all the MongoDB features I need
Been running this in production for 6 months now. If anyone else is dealing with the “MongoDB + serverless” headache, this might save you some pain.
Docs: https://mondel-orm.pages.dev
NPM: https://www.npmjs.com/package/mondel
Bonus: Works everywhere else too
-
Node.js (traditional servers) - persistent connections
-
Bun - super fast runtime support
-
Deno - edge runtime compatible
-
Vercel Edge, AWS Lambda - all serverless platforms
// Node.js mode - connects immediately
const db = await createClient({ uri: process.env.MONGODB_URI, schemas: [userSchema], });
Full disclosure: I’ve been using this in production and just published it to NPM today as v0.2.0. It’s been battle-tested in my apps but would love feedback from others dealing with the same MongoDB + serverless headaches.
What solutions have you guys found for MongoDB in serverless?