MongoDB ODM for AdonisJS v6

A familiar Lucid ORM-like interface for working with MongoDB databases. Featuring decorator-based models, fluent query builder, and full TypeScript support.

Features

Everything you need for MongoDB

Built with developer experience in mind, featuring familiar patterns from Lucid ORM.

Familiar API

Similar to AdonisJS Lucid ORM for easy adoption by existing AdonisJS developers.

Decorator-based Models

Use decorators to define your model schema with full TypeScript support.

Fluent Query Builder

Chainable query methods with MongoDB-specific operations and intuitive syntax.

Embedded Documents

Type-safe embedded document support with full CRUD operations and query builders.

ACID Transactions

Full ACID transaction support with managed and manual modes for data consistency.

TypeScript First

Built with TypeScript from the ground up with full IntelliSense support.

Quick Example

Get started in minutes

Define your model

import { BaseModel, column } from 'adonis-odm'
import { DateTime } from 'luxon'

export default class User extends BaseModel {
  @column({ isPrimary: true })
  declare _id: string

  @column()
  declare name: string

  @column()
  declare email: string

  @column.dateTime({ autoCreate: true })
  declare createdAt: DateTime

  @column.dateTime({ autoCreate: true, autoUpdate: true })
  declare updatedAt: DateTime
}

Use the fluent API

// Create a user
const user = await User.create({
  name: 'John Doe',
  email: '[email protected]'
})

// Query with fluent API
const adults = await User.query()
  .where('age', '>=', 18)
  .where('email', 'like', '%@gmail.com')
  .orderBy('createdAt', 'desc')
  .paginate(1, 10)

// Use transactions
await db.transaction(async (trx) => {
  const user = await User.create({
    name: 'Jane Smith',
    email: '[email protected]'
  }, { client: trx })

  // More operations...
})

Ready to get started?

Install Adonis ODM and start building with MongoDB today.