This project uses MongoDB 5.0 docker image and is designed to easily operate a MongoDB cluster using Docker.
| Key | Type | Default | Description |
|---|---|---|---|
| MONGO_PRIMARY_PORT | number | 27017 | Mongo db primary cluster external port |
| MONGO_SECONDARY_READ_PORT | number | 27018 | Mongo db secondary read cluster external port |
| MONGO_SECONDARY_RW_PORT | number | 27019 | Mongo db secondary read/write cluster external port |
| MONGO_INITDB_ROOT_USERNAME | string | root | Mongo db root username |
| MONGO_INITDB_ROOT_PASSWORD | string | 1234 | Mongo db root user default password |
| MONGO_INITDB_DATABASE | string | product | Mongo db test database name |
$ copy .env.example .envCreate .env file by copying .env.example and modify the values for each key as needed:
$ cp .env.example .envGive execution permissions to all shell scripts:
$ chmod +x deploy.shRun deploy.sh to start MongoDB cluster:
$ ./deploy.shThis will:
- Create MongoDB SSL key if not exists
- Write environment variables if not exists
- Start MongoDB containers
- Initialize replica set
- Check replica set status
To stop the MongoDB containers:
$ ./shutdown.shTo remove all containers and data:
$ ./clean-up.shThis will remove:
- All MongoDB containers
- All MongoDB data volumes
- Environment files