3.0.1 • Published 5 years ago

mongoose-nconf-connect v3.0.1

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

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
}    
3.0.1

5 years ago

3.0.0

5 years ago

2.2.0

6 years ago

2.1.0

6 years ago

2.0.0

6 years ago

1.2.4

7 years ago

1.2.1

8 years ago

1.2.0

8 years ago

1.1.0

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago