Registry / database / mongo-adonis

mongo-adonis

JSON →
library2.1.0jsnpmunverified

MongoDB adapter for Lucid ORM (AdonisJS 6), version 2.1.0. Actively developed with over 100 tests, enabling MongoDB integration using the familiar Lucid ORM API with full TypeScript support. Supports Active Record pattern, decorators, relationships (HasOne, HasMany, BelongsTo), and direct MongoDB access. Requires @adonisjs/core ^6.0.0. Not yet production-ready; roadmap includes pagination, migrations, factories and seeds. Peer dependencies: @adonisjs/core. Node >=16.

npm install mongo-adonis
INSTALL
IMPORT
SIG · MONGO-ADONIS
M
mongo-adonis
databasejavascriptv2.1.0
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.

MongoModel
import { MongoModel } from 'mongo-adonis'
const MongoModel = require('mongo-adonis').MongoModel
ESM-only. AdonisJS 6 uses ES modules natively.
column
import { column } from 'mongo-adonis'
Decorator for defining model columns.
ObjectId
import { ObjectId } from 'mongo-adonis'
import { ObjectId } from 'mongodb'
Exported from mongo-adonis; directly using mongodb's ObjectId may cause type mismatches.
hasMany
import { hasMany } from 'mongo-adonis'
import { hasMany } from '@adonisjs/lucid'
Lucid's hasMany is not compatible; use mongo-adonis's implementation.

Defines a User model using MongoModel decorators and performs basic CRUD operations (create, read, update, delete).

import { MongoModel, column, ObjectId } from 'mongo-adonis' export class User extends MongoModel { @column({ isPrimary: true }) declare _id: ObjectId @column() declare name: string @column() declare email: string @column() declare password: string } // Create a user const user = await User.create({ name: 'John Doe', email: 'john@example.com', password: 'secret' }) // Query all users const users = await User.all() // Update user.name = 'Jane Doe' await user.save() // Delete await user.delete()
Debug
Known issues
deprecated
affects: >=2.0.0
breakingPackage is in active development with possible breaking changes between minor versions.
fix
Pin exact version or test upgrades thoroughly.
affects: >=2.0.0
gotchaObjectId must be imported from 'mongo-adonis', not 'mongodb'.
fix
import { ObjectId } from 'mongo-adonis'
affects: >=2.0.0
gotchaRelationship decorators (hasMany, belongsTo) are from 'mongo-adonis', not '@adonisjs/lucid'.
fix
import { hasMany, belongsTo } from 'mongo-adonis'
affects: >=2.0.0
Errors
Common errors & fixes
Cannot find module 'mongo-adonis'
Missing package installation or incorrect import path.
fix
Run: bun install mongo-adonis
Property 'create' does not exist on type 'typeof User'
Model class not extending MongoModel or using wrong import.
fix
Ensure class extends MongoModel: export class User extends MongoModel { ... }
Cannot use import statement outside a module
AdonisJS 6 project not configured for ESM.
fix
Add "type": "module" in package.json or use .mjs extension.
Upgrade
Version history
2.1.0latest on npm
Audit
Dependencies
@adonisjs/corerequiredpeer dependency required for AdonisJS 6 integration
Agent activity
4 hits · last 30 days
node
4
Resources
mongo-adonis — npm install mongo-adonis · libregistry