Registry / database / architect-mongodb-native

architect-mongodb-native

JSON →
library4.0.0jsnpmunverified

Exposes a MongoDB client as an Architect plugin. Version 4.0.0 is the latest stable release, published on an as-needed cadence. It wraps the official mongodb-native driver and integrates seamlessly with the Architect dependency injection framework. Supports single and multiple MongoDB connections, custom configuration via url and config objects, and logging levels. Differentiates from plain mongodb-native by providing a declarative plugin interface for Architect-based applications.

npm install architect-mongodb-native
INSTALL
IMPORT
SIG · ARCHITECT-MONGODB-
A
architect-mongodb-native
databasejavascriptv4.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.

mongo
// In plugin config: consumes: ['mongo']
// Direct require not typical; the service is injected by Architect
The mongo service is provided by Architect via plugin registration; you don't import it directly.
setup function
module.exports = function setup(options, imports, register) { var db = imports.mongo.db; ... }
// Common mistake: using imports.mongo instead of imports.mongo.db
The mongo object contains db (the Db instance) and possibly other properties; db is the main property used.
config file
module.exports = [ { packagePath: 'architect-mongodb-native', url: 'mongodb://...' }, ... ]
// Wrong: missing packagePath or incorrect url format
Config file is an array of plugins; architect-mongodb-native expects a 'url' string; multiple connections use named objects.

Configures a single MongoDB connection and uses the db instance in a plugin.

// config.js module.exports = [{ packagePath: 'architect-mongodb-native', url: 'mongodb://127.0.0.1:27017/test', }, './routes']; // routes/index.js module.exports = function setup(options, imports, register) { var db = imports.mongo.db; db.collection('test').update({hi: 'here'}, {$set: {hi: 'there'}}, {w:1}, function(err) { if (err) console.warn(err.message); else console.log('successfully updated'); }); register(); }; // app.js var path = require('path'); var architect = require('architect'); var configPath = path.join(__dirname, 'config.js'); var config = architect.loadConfig(configPath); architect.createApp(config, function (err, app) { if (err) throw err; console.log('application started'); });
Debug
Known issues
breakingv4.0.0 may have dropped support for older Node.js versions; requires Node >=16.20.1.
fix
Update Node.js to >=16.20.1.
affects: >=4.0.0
deprecatedThe mongodb native driver has deprecated the old callback-based API; use promises or async/await instead.
fix
Use db.collection('test').updateOne(...).then(...) or await.
affects: all
gotchaThe 'mongo' service is an object with a 'db' property; direct usage of imports.mongo as the database will fail.
fix
Access the database via imports.mongo.db.
affects: >=1.0.0
gotchaMultiple connections: use named objects like 'first' and 'second' inside the plugin config; the services become imports.mongo.first.db and imports.mongo.second.db.
fix
Use the correct service path for each named connection.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: Cannot read property 'db' of undefined
The 'mongo' service was not injected because the plugin does not consume it or the plugin is not loaded correctly.
fix
Ensure your plugin config includes 'consumes: ["mongo"]' and that architect-mongodb-native is declared as a dependency in your config file.
Error: connect ECONNREFUSED 127.0.0.1:27017
MongoDB is not running on the specified host/port, or the url is incorrect.
fix
Start MongoDB or correct the url in your plugin config.
MongoError: auth fails
MongoDB credentials are missing or incorrect in the url.
fix
Include credentials in the url, e.g., mongodb://user:pass@127.0.0.1:27017/test, or use config options.
Upgrade
Version history
4.0.0latest on npm
Audit
Dependencies
mongodbrequiredMongoDB native driver for database operations
Agent activity
19 hits · last 30 days
node
16
OpenAI (training)
1
Resources
architect-mongodb-native — npm install architect-mongodb-native · libregistry