Registry /
database / architect-mongodb-native
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');
});
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.
fixEnsure 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.
fixStart MongoDB or correct the url in your plugin config.
MongoError: auth fails
MongoDB credentials are missing or incorrect in the url.
fixInclude credentials in the url, e.g., mongodb://user:pass@127.0.0.1:27017/test, or use config options.
Audit
Dependencies
mongodbrequiredMongoDB native driver for database operations