Skip to content
This repository was archived by the owner on Mar 17, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,8 @@ The connection can also be automatically initiated through the environment (or w
|Env-variable|Description|
|--- |--- |
|`CONN_NAME`|The name of the connection to create on boot|
|`DB_USERNAME`|The username for the database connection|
|`DB_PASSWORD`|The password for the database user|
|`DB_HOST`|The host IP address or DNS name without the port!|
|`DB_PORT`|The port of the mongoDB database, if not provided the default 27017 will be used|
|`DB_NAME`|The name of the database|
|`CONN_URI`|Full connection URI (should include `mongo://`)|
|`CONN_OPTS`|Connection options in (e.g., `{"replicaSet": "rs0"}`|

*The Connection setup screen*
![adminMongo connections screen](https://raw.githubusercontent.com/mrvautin/mrvautin.github.io/master/images/adminMongo/adminMongo_connections.png "adminMongo connections screen")
Expand Down
15 changes: 3 additions & 12 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,19 +111,10 @@ if(!fs.existsSync(config_app)) fs.writeFileSync(config_app, JSON.stringify(confi
var configConnection = {
connections: {}
};
if(process.env.CONN_NAME && process.env.DB_HOST) {
if(!process.env.DB_PORT) process.env.DB_PORT = '27017'; // Use the default mongodb port when DB_PORT is not set
var connectionString = 'mongodb://';
if(process.env.DB_USERNAME && process.env.DB_PASSWORD && process.env.DB_NAME) {
connectionString += process.env.DB_USERNAME + ':' + process.env.DB_PASSWORD + '@' + process.env.DB_HOST + ':' + process.env.DB_PORT + '/' + process.env.DB_NAME;
}else if (process.env.DB_USERNAME && process.env.DB_PASSWORD) {
connectionString += process.env.DB_USERNAME + ':' + process.env.DB_PASSWORD + '@' + process.env.DB_HOST + ':' + process.env.DB_PORT + '/'
} else {
connectionString += process.env.DB_HOST + ':' + process.env.DB_PORT
}
if(process.env.CONN_NAME && process.env.CONN_URI) {
configConnection.connections[process.env.CONN_NAME] = {
connection_options: {},
connection_string: connectionString
connection_options: JSON.parse(process.env.CONN_OPTS),
connection_string: process.env.CONN_URI
};
}
if (!fs.existsSync(config_connections) || fs.readFileSync(config_connections, 'utf8') === '{}')
Expand Down