Registry / database / systemic-mongodb

systemic-mongodb

JSON →
library2.1.0jsnpmunverified

A systemic component for MongoDB that integrates with the systemic dependency injection framework. Current stable version is 2.1.0. It wraps the native MongoDB driver to provide a configurable, lifecycle-managed MongoDB client within a systemic application. Release cadence is low, with updates driven by MongoDB driver changes. Key differentiator: it handles connection lifecycle (connect/disconnect) and exposes a configured MongoClient instance as a systemic component, simplifying dependency injection setups. It supports connection string, options, and logging configuration.

npm install systemic-mongodb
INSTALL
IMPORT
SIG · SYSTEMIC-MONGODB
S
systemic-mongodb
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.

default
const mongodb = require('systemic-mongodb')
import mongodb from 'systemic-mongodb'
Package is CommonJS only; ESM import may fail without default export.
systemic-mongodb as factory
const mongodb = require('systemic-mongodb')
const { mongodb } = require('systemic-mongodb')
The default export is a factory function, not a named export. Destructuring will yield undefined.
systemic component registration
system.add('mongodb', mongodb()).dependsOn('config', 'logger')
system.add('mongodb', mongodb)
The factory must be called (mongodb()) to return the actual component definition. Passing the function itself will not work.

Shows how to configure and use the systemic-mongodb component with a MongoDB connection, including error handling and basic collection query.

const System = require('systemic'); const mongodb = require('systemic-mongodb'); const system = new System(); system .configure({ mongodb: { url: process.env.MONGODB_URL || 'mongodb://127.0.0.1/example', options: { server: { poolSize: 5 } }, showConnectionString: false } }) .add('logger', console) .add('mongodb', mongodb()).dependsOn('config', 'logger') .start((err, components) => { if (err) { console.error('Failed to start system', err); process.exit(1); } // Access the MongoDB client via components.mongodb.client const client = components.mongodb; client.db().collection('test').find({}).toArray() .then(docs => console.log(docs)) .catch(err => console.error(err)); });
Debug
Known issues
gotchaThe component does not expose a 'db' instance; it exposes the MongoClient object. Use client.db() to get a database reference.
fix
Access the MongoDB client via components.mongodb, then call client.db('dbname').
affects: >=1.0.0
gotchaThe factory must be invoked (mongodb()) when adding to the system, not passed as a reference.
fix
Use .add('mongodb', mongodb()).dependsOn(...) instead of .add('mongodb', mongodb).
affects: >=1.0.0
breakingOptions passed to MongoDB driver changed between driver versions; systemic-mongodb v2.x uses the native driver v3+ options format, which is different from v1.x with driver v2.
fix
Refer to MongoDB Node.js driver v3+ documentation for correct options structure.
affects: >=2.0.0
deprecatedThe 'showConnectionString' parameter defaults to false to avoid logging sensitive strings. Setting it to true exposes connection details in logs.
fix
Keep showConnectionString: false in production to avoid leaking credentials.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: mongodb is not a function
The factory function was not required correctly; the default export is a function but sometimes imported as an object.
fix
Use const mongodb = require('systemic-mongodb'); and then call mongodb()
Cannot read property 'db' of undefined
The component did not start correctly due to missing dependencies or configuration.
fix
Ensure 'config' and 'logger' dependencies are added before 'mongodb' and that 'config.mongodb' has the required 'url' property.
MongoError: failed to connect to server on first connect
The MongoDB server is not running or the connection URL is incorrect.
fix
Verify MongoDB server is running and the URL is correct (e.g., mongodb://127.0.0.1:27017/example).
Upgrade
Version history
2.1.0latest on npm
Audit
Dependencies
mongodbrequiredCore MongoDB driver
systemicrequiredRequired to use the component in a systemic application
Agent activity
17 hits · last 30 days
node
14
Meta
2
OpenAI (training)
1
Resources
systemic-mongodb — npm install systemic-mongodb · libregistry