From 7ad4420b6ac205216291f7dc96017b2cb29a4aab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Mon, 23 Oct 2017 15:09:13 -0400 Subject: [PATCH] closes #6000 --- install/databases.js | 3 ++- src/database/mongo.js | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/install/databases.js b/install/databases.js index 6a8d68d633..b55fa8ad0c 100644 --- a/install/databases.js +++ b/install/databases.js @@ -34,7 +34,7 @@ function getDatabaseConfig(config, callback) { prompt.get(questions.redis, callback); } } else if (config.database === 'mongo') { - if (config['mongo:host'] && config['mongo:port']) { + if ((config['mongo:host'] && config['mongo:port']) || config['mongo:uri']) { callback(null, config); } else { prompt.get(questions.mongo, callback); @@ -68,6 +68,7 @@ function saveDatabaseConfig(config, databaseConfig, callback) { username: databaseConfig['mongo:username'], password: databaseConfig['mongo:password'], database: databaseConfig['mongo:database'], + uri: databaseConfig['mongo:uri'], }; } else { return callback(new Error('unknown database : ' + config.database)); diff --git a/src/database/mongo.js b/src/database/mongo.js index c79ee81bdc..fbe4b38a03 100644 --- a/src/database/mongo.js +++ b/src/database/mongo.js @@ -8,37 +8,52 @@ var nconf = require('nconf'); var session = require('express-session'); var _ = require('lodash'); var semver = require('semver'); +var prompt = require('prompt'); var db; var mongoModule = module.exports; +function isUriNotSpecified() { + return !prompt.history('mongo:uri').value; +} + mongoModule.questions = [ + { + name: 'mongo:uri', + description: 'MongoDB connection URI: (leave blank if you wish to specify host, port, username/password and database individually)\nFormat: mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[database][?options]]', + default: nconf.get('mongo:uri') || '', + }, { name: 'mongo:host', description: 'Host IP or address of your MongoDB instance', default: nconf.get('mongo:host') || '127.0.0.1', + ask: isUriNotSpecified, }, { name: 'mongo:port', description: 'Host port of your MongoDB instance', default: nconf.get('mongo:port') || 27017, + ask: isUriNotSpecified, }, { name: 'mongo:username', description: 'MongoDB username', default: nconf.get('mongo:username') || '', + ask: isUriNotSpecified, }, { name: 'mongo:password', description: 'Password of your MongoDB database', - hidden: true, default: nconf.get('mongo:password') || '', + hidden: true, + ask: isUriNotSpecified, before: function (value) { value = value || nconf.get('mongo:password') || ''; return value; }, }, { name: 'mongo:database', description: 'MongoDB database name', default: nconf.get('mongo:database') || 'nodebb', + ask: isUriNotSpecified, }, ];