Skip to content

Node.js based forum software built for the modern web

closes #6000

Barış Soner Uşaklı7ad4420b6ac2
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,
},
];