Registry / database / adonis-mongodb

adonis-mongodb

JSON →
library1.0.0jsnpmunverified

AdonisJS provider to integrate MongoDB into AdonisJS applications using the official MongoDB Node.js driver. Version 1.0.0 is the latest stable release, compatible with @adonisjs/fold ^4.0.9 and mongodb ^3.3.5. This package provides a simple way to register MongoDB as a service provider in AdonisJS, allowing dependency injection of a MongoDB client instance throughout the app. It is a lightweight alternative to full-featured ODM libraries like Mongoose, targeting developers who prefer the native driver within AdonisJS. The project is maintained but has limited community adoption and documentation.

npm install adonis-mongodb
INSTALL
IMPORT
SIG · ADONIS-MONGODB
A
adonis-mongodb
databasejavascriptv1.0.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.

MongoProvider
import { MongoProvider } from 'adonis-mongodb'
import MongoProvider from 'adonis-mongodb'
Named export, not default.
Mongo
const Mongo = use('Mongo')
import { Mongo } from 'adonis-mongodb'
Mongo is not exported from the package; it is registered as an alias in AdonisJS IoC.
start/app.js registration
const providers = ['adonis-mongodb/providers/MongoProvider']
import { MongoProvider } from 'adonis-mongodb'
Provider must be registered via string path in start/app.js.

Shows provider registration and basic usage to query a MongoDB collection.

// In start/app.js const providers = [ 'adonis-mongodb/providers/MongoProvider' ] // In any service or controller const Database = use('Mongo') const collection = Database.collection('users') const users = await collection.find().toArray() // Environment variable for connection string (in .env) // MONGODB_URL=mongodb://localhost:27017/myapp
Debug
Known issues
gotchaMongoDB client is shared as a singleton; ensure you do not close the connection manually or it will break all subsequent requests.
fix
Do not call client.close() – let the provider manage connection lifecycle.
affects: >=1.0.0
deprecatedThis package is compatible with AdonisJS 4.x only; not updated for AdonisJS 5.x.
fix
If using AdonisJS 5, consider using @adonisjs/lucid with MongoDB adapter or adonis5-mongodb.
affects: >=1.0.0
gotchaThe provider does not support connection pooling configuration out of the box; you must configure via the MongoDB URL string.
fix
Append pool options to MONGODB_URL, e.g., mongodb://localhost:27017/myapp?maxPoolSize=10
affects: >=1.0.0
breakingRequires @adonisjs/fold version ^4.0.9 and mongodb version ^3.3.5; incompatible with newer major versions.
fix
Ensure your project uses the specified peer dependency versions.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'adonis-mongodb/providers/MongoProvider'
Provider path is incorrect or package not installed.
fix
Run `adonis install adonis-mongodb` and verify the provider path is exactly 'adonis-mongodb/providers/MongoProvider'
ReferenceError: use is not defined
Using use() outside of AdonisJS context (e.g., in a standalone script).
fix
Use() is only available within AdonisJS controllers, services, etc. For external scripts, require the IoC container.
TypeError: Cannot read property 'collection' of undefined
MongoDB client is not initialized; missing MONGODB_URL environment variable.
fix
Set MONGODB_URL in .env file and restart the server.
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies
@adonisjs/foldrequiredCore dependency for AdonisJS IoC container integration (version 4.x)
mongodbrequiredOfficial MongoDB driver for Node.js (version 3.x)
Agent activity
28 hits · last 30 days
node
24
OpenAI (training)
1
Resources
adonis-mongodb — npm install adonis-mongodb · libregistry