Type-safe MongoDB ODM for TypeScript

MonarchORM

Use MongoDB without losing the type safety we all love. Experience the perfect balance of speed, type safety, and flexibility.

models/user.ts
1import { createSchema, createClient, createDatabase, string, number, createdAt } from 'monarch-orm';
2
3// Define your schema with full type safety
4const users = createSchema('users', {
5 name: string(),
6 email: string(),
7 age: number(),
8 createdAt: createdAt()
9});
10
11// Create a client and connect to your MongoDB database
12const client = createClient('mongodb://localhost:27017/my-database');
13const { collections } = createDatabase(client, { users });
14
15// Query with type-safe methods
16const users = await collections.users
17 .find({ age: { $gte: 21 } })
18 .sort({ createdAt: -1 })
19 .limit(10);
20

Type safety from schema to query results

Define your MongoDB schema once, get complete type safety everywhere.

No more type errors at runtime despite using TypeScript. MonarchORM maintains complete type safety from schema definition to query results, providing accurate IntelliSense in your IDE and catching errors before they happen.

Schema
import { createSchema, string, number, literal, objectId, createdAt, updatedAt } from "monarch-orm";
const userSchema = createSchema('users', {
name: string(),
email: string(),
age: number(),
role: literal("admin", "user").default("user"),
profile: objectId(),
createdAt: createdAt(),
updatedAt: updatedAt()
});
// Type-safety guaranteed - no runtime surprises
type User = InferSchemaOutput<typeof userSchema>;

Intuitive queries with zero compromises

Write MongoDB queries with confidence using autocompletion and validation.

MonarchORM's fluent query builder provides autocomplete for operators and fields, catches errors at compile time, and maintains the full power of MongoDB's query capabilities without sacrificing flexibility.

Query
// All queries are fully type-safe and autocompletable
const users = await collections.users.find({
role: "admin",
createdAt: { $gt: new Date("2023-01-01") }
},
}).sort({
createdAt: "desc"
}).populate({
profile: true
}).limit(10);
// 'users' is fully typed with proper references

Painless schema evolution

Evolve your database schema with confidence using type-safe migrations.

MonarchORM provides tools to safely update schemas, validate existing data, and ensure backward compatibility, making migrations less painful and error-prone.

Schema
// Create a new migration
const migration = monarch.createMigration({
name: "add-verification-fields",
up: async (db) => {
await db.updateSchema("users", {
// Add new fields to existing schema
fields: {
isVerified: MonarchSchema.Boolean.default(false),
verificationToken: MonarchSchema.String.optional(),
}
});
// Backfill data if needed
await db.updateMany({
collection: "users",
where: { email: { $contains: "@verified.com" } },
data: { isVerified: true }
});
},
down: async (db) => {
// Revert changes safely
await db.updateSchema("users", {
remove: ["isVerified", "verificationToken"]
});
}
});

Lightning Fast

Optimized queries and efficient caching for blazing-fast performance.

Type-Safe

Full TypeScript support with static type checking for your MongoDB schemas.

Developer Friendly

Intuitive API with excellent IDE support for a smooth development experience.

Seamless Integration

Define complex schemas with ease, including nested objects and arrays.

Auto-completion

Enjoy intelligent auto-completion for your models and queries.

Easy Migration

Seamlessly migrate from other ORMs with our compatibility layer.

Unmatched Speed

Monarch ORM outperforms other popular ODMs and ORMs, providing lightning-fast query execution and minimal overhead.

Monarch ORM
Prisma
Mongoose
2x Faster

Monarch ORM vs. Others

FeaturesMonarch ORMNative DriverMongoose
Type Safety
MongoDB Support
Query Performance
Schema Definition
IDE Autocompletion

Ready to Build Faster?

Try our ORM today and experience the difference. Whether you're migrating from another tool or starting fresh, you'll love the simplicity and speed.

Join Our Community

Get help, share ideas, and collaborate with other developers

GitHub

Star the repo, report issues, and contribute to the codebase.

View Repository

Documentation

Explore our comprehensive guides, tutorials, and API references.

Read Docs