mongo.js
821 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// # boot - mongo
var mongoose = require('mongoose')
var _ = require('underscore')
exports = module.exports = function(logger, settings) {
var connection
if (_.isString(settings.mongo.uri)) {
connection = mongoose.createConnection(settings.mongo.uri, settings.mongo.opts)
} else {
connection = mongoose.createConnection(
settings.mongo.host,
settings.mongo.dbname,
settings.mongo.port,
settings.mongo.opts
)
}
connection.on('error', function(err) {
logger.error('mongo connection error: %s', err.message || err)
})
connection.on('open', function() {
logger.info('mongo connection opened')
})
connection = _.defaults(connection, mongoose)
return connection
}
exports['@singleton'] = true
exports['@require'] = [ 'igloo/logger', 'igloo/settings' ]