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.
A familiar Lucid ORM-like interface for working with MongoDB databases. Featuring decorator-based models, fluent query builder, and full TypeScript support.
Everything you need for MongoDB
Built with developer experience in mind, featuring familiar patterns from Lucid ORM.
Familiar API
Decorator-based Models
Fluent Query Builder
Embedded Documents
ACID Transactions
TypeScript First
Get started in minutes
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
}
// 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...
})
Install Adonis ODM and start building with MongoDB today.