3.0.0 • Published 12 months ago

architect-mongodb-native v3.0.0

Weekly downloads
3
License
Apache License V2
Repository
github
Last release
12 months ago

architect-mongodb-native

Expose a mongodb client as architect plugin.

Installation

npm install --save architect-mongodb-native

Config Format

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

Supported config elements

url

MongoDB server url.

config

Additional mongodb config parameters.

Usage

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 (err, app) {
    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(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();
};

Options

  • url : mongoclient connect url
  • config : additionnal connection parameter
  • config.logger: 'error', 'info', 'debug' enable mongodb driver logs with the selected level.

multiple connections

Multiple mongo connection are supported. For instance :

module.exports = [{
    packagePath: "architect-mongodb-native",
    first:{
      url : 'mongodb://127.0.0.1:27017/test'
    },
    second:{
      url : 'mongodb://127.0.0.1:27017/other'
    },
    config: {
      readPreference: 'secondaryPreferred',
      replicaSet: 'myreplset'
    }
}, './routes'];
3.0.0

12 months ago

2.1.0

12 months ago

2.0.3

2 years ago

2.0.2

3 years ago

2.0.1

3 years ago

2.0.0

4 years ago

1.3.2

5 years ago

1.3.1

6 years ago

1.3.0

7 years ago

1.2.0

7 years ago

1.0.1

9 years ago

1.0.0

9 years ago

0.0.2

10 years ago

0.0.1

10 years ago