From 5b7423cef25d04bf361fd5f916d1dd282a2f96c8 Mon Sep 17 00:00:00 2001 From: Liran Tal Date: Sat, 29 Nov 2014 11:06:16 +0200 Subject: [PATCH] updating support for mongodb connection string to support special chars for username and password --- config/env/development.js | 8 +++++++- config/env/production.js | 8 +++++++- config/env/secure.js | 8 +++++++- config/env/test.js | 8 +++++++- server.js | 2 +- 5 files changed, 29 insertions(+), 5 deletions(-) diff --git a/config/env/development.js b/config/env/development.js index 2b895b8bbc..35c08b7e8e 100644 --- a/config/env/development.js +++ b/config/env/development.js @@ -1,7 +1,13 @@ 'use strict'; module.exports = { - db: 'mongodb://localhost/mean-dev', + db: { + uri: 'mongodb://localhost/mean-dev', + options: { + user: '', + pass: '' + } + }, log: { // Can specify one of 'combined', 'common', 'dev', 'short', 'tiny' format: 'dev', diff --git a/config/env/production.js b/config/env/production.js index c9f2817382..a56a48f0e5 100644 --- a/config/env/production.js +++ b/config/env/production.js @@ -1,7 +1,13 @@ 'use strict'; module.exports = { - db: process.env.MONGOHQ_URL || process.env.MONGOLAB_URI || 'mongodb://' + (process.env.DB_1_PORT_27017_TCP_ADDR || 'localhost') + '/mean', + db: { + uri: process.env.MONGOHQ_URL || process.env.MONGOLAB_URI || 'mongodb://' + (process.env.DB_1_PORT_27017_TCP_ADDR || 'localhost') + '/mean', + options: { + user: '', + pass: '' + } + }, log: { // Can specify one of 'combined', 'common', 'dev', 'short', 'tiny' format: 'combined', diff --git a/config/env/secure.js b/config/env/secure.js index ee2b270ad1..16400219b5 100644 --- a/config/env/secure.js +++ b/config/env/secure.js @@ -2,7 +2,13 @@ module.exports = { port: 443, - db: process.env.MONGOHQ_URL || process.env.MONGOLAB_URI || 'mongodb://localhost/mean', + db: { + uri: process.env.MONGOHQ_URL || process.env.MONGOLAB_URI || 'mongodb://localhost/mean', + options: { + user: '', + pass: '' + } + }, log: { // Can specify one of 'combined', 'common', 'dev', 'short', 'tiny' format: 'combined', diff --git a/config/env/test.js b/config/env/test.js index 22c47c9fb2..1d42d4e798 100644 --- a/config/env/test.js +++ b/config/env/test.js @@ -1,7 +1,13 @@ 'use strict'; module.exports = { - db: 'mongodb://localhost/mean-test', + db: { + uri: 'mongodb://localhost/mean-test', + options: { + user: '', + pass: '' + } + }, port: 3001, log: { // Can specify one of 'combined', 'common', 'dev', 'short', 'tiny' diff --git a/server.js b/server.js index 8f54163280..b996fcaf36 100755 --- a/server.js +++ b/server.js @@ -13,7 +13,7 @@ var init = require('./config/init')(), */ // Bootstrap db connection -var db = mongoose.connect(config.db, function(err) { +var db = mongoose.connect(config.db.uri, config.db.options, function(err) { if (err) { console.error(chalk.red('Could not connect to MongoDB!')); console.log(chalk.red(err));