architect-mongodb-native

Expose a mongodb client as architect plugin.

architect-mongodb-native

Expose a mongodb client as architect plugin.

npm install --save architect-mongodb-native
{
  "packagePath": "architect-mongodb-native",
  "url": "mongodb://127.0.0.1:27017/test"
}

MongoDB server url.

Additional mongodb config parameters.

Boot Architect :

var path = require('path');
var architect = require("architect");
 
var configPath = path.join(__dirname, "config.js");
var config = architect.loadConfig(configPath);
 
architect.createApp(config, function (errapp) {
    if (err) {
        throw err;
    }
    console.log('application started');
});

Configure mongodb with config.js :

module.exports = [{
    packagePath: "architect-mongodb-native",
    url : 'mongodb://127.0.0.1:27017/test'
}, './routes'];

Consume mongo service in your application :

{
  "name": "routes",
  "version": "0.0.1",
  "main": "index.js",
  "private": true,
 
  "plugin": {
    "consumes": ["mongo"]
  }
}

Eventually use the mongo service in your app :

module.exports = function setup(optionsimportsregister) {
    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();
};