Browse Source

Merge pull request #195 from isocolsky/ref/mongo_uri

make mongodb uri configurable
activeAddress
Matias Alejo Garcia 10 years ago
parent
commit
784e3d956c
  1. 3
      config.js
  2. 7
      lib/storage.js

3
config.js

@ -13,8 +13,7 @@ var config = {
storageOpts: { storageOpts: {
mongoDb: { mongoDb: {
host: 'localhost', uri: 'mongodb://localhost:27017/bws',
port: 27017,
}, },
}, },
lockOpts: { lockOpts: {

7
lib/storage.js

@ -33,14 +33,13 @@ Storage.prototype.connect = function(opts, cb) {
if (this.db) return cb(null); if (this.db) return cb(null);
var config = opts.mongoDb || {}; var config = opts.mongoDb || {};
var url = 'mongodb://' + (config.host || 'localhost') + ':' + (config.port ||  27017) + '/bws'; mongodb.MongoClient.connect(config.uri, function(err, db) {
mongodb.MongoClient.connect(url, function(err, db) {
if (err) { if (err) {
log.error('Unable to connect to the mongoDB server.'); log.error('Unable to connect to the mongoDB server on ', config.uri);
return cb(err); return cb(err);
} }
self.db = db; self.db = db;
console.log('Connection established to ', url); console.log('Connection established to ', config.uri);
return cb(null); return cb(null);
}); });
}; };

Loading…
Cancel
Save