Skip to content

Commit

Permalink
+ Fix invalid config fallback values fixes mongo-express#655, mongo-e…
Browse files Browse the repository at this point in the history
…xpress#703, mongo-express#617

+ Remove extra parameters documentation for connection config
  • Loading branch information
JafarAkhondali committed May 30, 2021
1 parent 59d04a3 commit cce68d8
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ EXPOSE 8081

# override some config defaults with values that will work better for docker
ENV ME_CONFIG_EDITORTHEME="default" \
ME_CONFIG_MONGODB_SERVER="mongo" \
ME_CONFIG_MONGODB_URL="mongodb://mongo:27017" \
ME_CONFIG_MONGODB_ENABLE_ADMIN="true" \
ME_CONFIG_BASICAUTH_USERNAME="" \
ME_CONFIG_BASICAUTH_PASSWORD="" \
Expand Down
18 changes: 5 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,15 @@ Fill in your MongoDB connection details and any other options you want to change

If you installed it globally, you can immediately start mongo-express like this:

mongo-express -u user -p password -d database

You can access a remote database by providing MongoDB Host and Port:

mongo-express -u user -p password -d database -H mongoDBHost -P mongoDBPort
mongo-express --url mongodb://127.0.0.1:27017

Or if you want to use it as an administrator:

mongo-express -a -u superuser -p password
mongo-express --admin --url mongodb://127.0.0.1:27017

For help on configuration options:

mongo-express -h
mongo-express --help

Usage (Express 4 middleware)
----------------------------
Expand All @@ -104,7 +100,7 @@ Usage (Express 4 middleware)
Usage (Docker)
--------------

Make sure you have a running [MongoDB container](https://hub.docker.com/_/mongo/) on a Docker network (`--network some-network` below) with `--name` or `--network-alias` set to `mongo`. Alternatively, set `ME_CONFIG_MONGODB_SERVER` to the name/alias of your MongoDB container on your Docker network.
Make sure you have a running [MongoDB container](https://hub.docker.com/_/mongo/) on a Docker network (`--network some-network` below) with `--name` or `--network-alias` set to `mongo`. Alternatively, set connection string `ME_CONFIG_MONGODB_URL` to the proper connection for your MongoDB container on your Docker network.

**Use [the Docker Hub image](https://hub.docker.com/_/mongo-express/):**

Expand All @@ -125,12 +121,8 @@ You can use the following [environment variables](https://docs.docker.com/refere

Name | Default | Description
----------------------------------|-----------------|------------
`ME_CONFIG_MONGODB_SERVER` |`mongo` or `localhost`| MongoDB host name or IP address. The default is `localhost` in the config file and `mongo` in the docker image. If it is a replica set, use a comma delimited list of the host names.
`ME_CONFIG_MONGODB_PORT` | `27017` | MongoDB port.
`ME_CONFIG_MONGODB_URL` | `mongodb://admin:pass@localhost:27017/db?ssl=false`
`ME_CONFIG_MONGODB_ENABLE_ADMIN` | `false` | Enable administrator access. Send strings: `"true"` or `"false"`.
`ME_CONFIG_MONGODB_ADMINUSERNAME` | ` ` | Administrator username.
`ME_CONFIG_MONGODB_ADMINPASSWORD` | ` ` | Administrator password.
`ME_CONFIG_MONGODB_AUTH_DATABASE` | `db` | Database name (only needed if `ENABLE_ADMIN` is `"false"`).
`ME_CONFIG_MONGODB_AUTH_USERNAME` | `admin` | Database username (only needed if `ENABLE_ADMIN` is `"false"`).
`ME_CONFIG_MONGODB_AUTH_PASSWORD` | `pass` | Database password (only needed if `ENABLE_ADMIN` is `"false"`).
Expand Down Expand Up @@ -167,7 +159,7 @@ You can use the following [environment variables](https://docs.docker.com/refere
-p 8081:8081 \
-e ME_CONFIG_OPTIONS_EDITORTHEME="ambiance" \
-e ME_CONFIG_BASICAUTH_USERNAME="" \
-e ME_CONFIG_MONGODB_SERVER="db" \
-e ME_CONFIG_MONGODB_URL="mongodb://mongo:27017" \
mongo-express

This example links to a container name typical of `docker-compose`, changes the editor's color theme, and disables basic authentication.
Expand Down
8 changes: 4 additions & 4 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ if (config.options.console) {
commander
.version(require('./package').version)
.option('-U, --url <url>', 'connection string url')
.option('-H, --host <host>', 'hostname or address of the db')
.option('-P, --dbport <host>', 'port of the db')
.option('-u, --username <username>', 'username for authentication')
.option('-p, --password <password>', 'password for authentication')
.option('-H, --host <host>', 'hostname or address of the db(deprecated)')
.option('-P, --dbport <host>', 'port of the db(deprecated)')
.option('-u, --username <username>', 'username for authentication(deprecated)')
.option('-p, --password <password>', 'password for authentication(deprecated)')
.option('-a, --admin', 'enable authentication as admin')
.option('-d, --database <database>', 'authenticate to database')
.option('--port <port>', 'listen on specified port')
Expand Down
6 changes: 4 additions & 2 deletions config.default.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
let mongo = {
// Setting the connection string will only give access to that database
// to see more databases you need to set mongodb.admin to true or add databases to the mongodb.auth list
// It is RECOMMENDED to use connectionString instead of individual params, other options will be removed later.
// More info here: https://docs.mongodb.com/manual/reference/connection-string/
connectionString: process.env.ME_CONFIG_MONGODB_SERVER ? '' : process.env.ME_CONFIG_MONGODB_URL,
host: '127.0.0.1',
port: '27017',
Expand Down Expand Up @@ -74,8 +76,8 @@ function getConnectionStringFromEnvVariables() {
// >>>> If you are using an admin mongodb account, or no admin account exists, fill out section below
// >>>> Using an admin account allows you to view and edit all databases, and view stats
// leave username and password empty if no admin account exists
username: getFileEnv(adminUsername) || getFileEnv(dbAuthUsername) || mongo.username || dbAuthUsername,
password: getFileEnv(adminPassword) || getFileEnv(dbAuthPassword) || mongo.password || dbAuthPassword,
username: getFileEnv(adminUsername) || getFileEnv(dbAuthUsername) || mongo.username,
password: getFileEnv(adminPassword) || getFileEnv(dbAuthPassword) || mongo.password,
};
const login = infos.username ? `${infos.username}:${infos.password}@` : '';
return `mongodb://${login}${infos.server}:${infos.port}/${infos.dbName}`;
Expand Down
2 changes: 1 addition & 1 deletion lib/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ const connect = async function (config) {
info: connectionInfo,
};
} catch (err) {
console.error(`Could not connect to database at index "${index}"`);
console.error(`Could not connect to database using connectionString: ${connectionString}"`);
throw err;
}
}));
Expand Down

0 comments on commit cce68d8

Please sign in to comment.