mongoose-nconf-connect
A simple way to connect mongoose using a standard layout in nconf
Last updated a year ago by real_ate .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install mongoose-nconf-connect 
SYNC missed versions from official npm registry.

Mongoose NConf Connect Build Status

This is a very simple module that takes mongoose and nconf and builds you a connection with config that is laid out in a "standard" way.

Usage

var mongooseConnect = require('mongoose-nconf-connect');

// Initialise the common connection
mongooseConnect.connectCommonMongo(nconf, mongoose);

// Get a connection and use it
mongooseConnect.getConnection().then(function(connection){
  //register models on the connection
  connection.model('myModel', mongoose.Schema({example: String})
})

It is important to note that getConnection() returns a promise. This allows us to use the nconf.get() async methods so that you can keep your config in redis for example.

You can also pass a logger (eg. winston instance) into mongooseConnect() so that it reports any connection errors.

// Initialise the common connection with winston
mongooseConnect.connectCommonMongo(nconf, mongoose, {logger: winston});

Config

The default config layout is like this:

{
    "mongo": {
        "db": "mySuperDatabase",
        "host": "localhost",
        "port": 27017
    }
}    

if you don't send a new prefix in the options to mongooseConnect this is where it will expect to find the config for your Mongodb host

you can even pass replica sets as an array of hosts here:

{
    "mongo": {
        "db": "mySuperDatabase",
        "host": ["host1", "host2", "host3"],
        "port": 27017
}    

Current Tags

  • 3.0.1                                ...           latest (a year ago)

11 Versions

  • 3.0.1                                ...           a year ago
  • 3.0.0                                ...           a year ago
  • 2.2.0                                ...           2 years ago
  • 2.1.0                                ...           2 years ago
  • 2.0.0                                ...           3 years ago
  • 1.2.4                                ...           3 years ago
  • 1.2.1                                ...           4 years ago
  • 1.2.0                                ...           4 years ago
  • 1.1.0                                ...           4 years ago
  • 1.0.1                                ...           4 years ago
  • 1.0.0                                ...           4 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 2
Dependencies (1)
  • q ^1.4.1
Dev Dependencies (12)

Copyright 2014 - 2016 © taobao.org |