{"id":18814927,"url":"https://github.com/simplymichael/mongo-db-replica-set","last_synced_at":"2026-01-13T09:30:16.710Z","repository":{"id":143894166,"uuid":"587894329","full_name":"simplymichael/mongo-db-replica-set","owner":"simplymichael","description":null,"archived":false,"fork":false,"pushed_at":"2023-01-12T18:19:04.000Z","size":10,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-12-30T00:50:39.417Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/simplymichael.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-01-11T20:50:34.000Z","updated_at":"2023-01-11T20:51:35.000Z","dependencies_parsed_at":null,"dependency_job_id":"74e96510-2beb-49c9-af2a-3fd3e7a14728","html_url":"https://github.com/simplymichael/mongo-db-replica-set","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simplymichael%2Fmongo-db-replica-set","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simplymichael%2Fmongo-db-replica-set/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simplymichael%2Fmongo-db-replica-set/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simplymichael%2Fmongo-db-replica-set/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/simplymichael","download_url":"https://codeload.github.com/simplymichael/mongo-db-replica-set/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239750929,"owners_count":19690743,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-07T23:47:01.536Z","updated_at":"2026-01-13T09:30:16.639Z","avatar_url":"https://github.com/simplymichael.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MongoDB Replica Set\n\nSetup a MongoDB Replica Set.\n\n## Tech stack \n- Node v16.15.1\n- NPM 8.12.1\n- Docker Compose \n\n## Prerequisites \n- Make sure you have Docker and Docker Compose installed\n- Install dependencies by running `npm install`\n- Copy and edit the **.env.example** file to **.env** file\n\n## Running\n- **Via NPM:** `npm run db:up`\n- **Via direct docker command:** `docker-compose up -d`\n\n\n## Logging into the docker containers and the DB\n- **Via NPM:**\n    - Run `npm run db:login \u003ctarget_container\u003e [command]`\n      This will log you into the home directory of the container specified by the `target_container` argument. \n      Available target containers are `primary`, `secondary`, and `tertiary`. \n  \n      The `primary` container acts as the primary (or master) for the replica set.\n      The `secondary` and `tertiary` containers are the secondary (or slave) for the replica set.\n\n      Once inside the container, run `mongo` to log into the database.\n      Then, from inside the database run `use DB_NAME`, \n      where `DB_NAME` is the database name specified in the *.env* file.\n      If you'd rather log directly into the database, specify `mongo` as the `[command]` option: \u003cbr /\u003e\n      `npm run db:login \u003ctarget_container\u003e mongo`. \n\n      Supported commands are `bash` (the default) and `mongo`.\n      The `mongo` command does not work for the `proxy` container. \n      Since it only serves to help us connect to the other containers \n      for initial setup of the replica set and for subsequent tasks such as backing up the DB, \n      we did not expose its port to the outside world. \n\n      **NOTE:** In place of *primary*, *secondary*, *tertiary*, and *proxy*, \n      you can use *1*, *2*, *3*, and *4* respectively instead.\n      The default is *primary*, the replica set master.\n\n## Stopping the containers \n- **Via NPM:**\n    - Stop the services but preserve the containers and data directory: `npm run db:stop`\n    - Stop the services and delete the containers: `npm run db:destroy`\n- **Via direct docker commands:** \n    - Stop the services but preserve the containers and data directory: `docker-compose stop`\n    - Stop the services and delete the containers: `docker-compose down`\n\nThere's no equivalent for deleting the data directory. \nTo delete the data directory, use the NPM commands as stated above \nor manually delete the `.data` directory.\n\n## To view logs\n- Run `docker-compose logs -f [OPTIONAL_SERVICE_NAME]`\n\n\n## Important notes\nTo start completely afresh,\ndelete the **/.data/mongodb/** directory directory.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimplymichael%2Fmongo-db-replica-set","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsimplymichael%2Fmongo-db-replica-set","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimplymichael%2Fmongo-db-replica-set/lists"}