{"id":24548075,"url":"https://github.com/imana97/mongodb-docker-compose-cluster","last_synced_at":"2026-05-07T21:36:49.086Z","repository":{"id":273439821,"uuid":"919098618","full_name":"imana97/MongoDB-docker-compose-cluster","owner":"imana97","description":"A production-ready MongoDB sharding cluster with Docker Compose, featuring 3 config servers, 7 shard servers, and a Mongos router. Includes automated initialization, resource optimization, persistent volumes, and MongoDB 8.0.4 support.","archived":false,"fork":false,"pushed_at":"2025-01-21T03:15:12.000Z","size":16,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-16T11:17:23.323Z","etag":null,"topics":["cluster","clustering","configserver","docker","docker-compose","mongo","router","shard"],"latest_commit_sha":null,"homepage":"","language":"Batchfile","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/imana97.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":"2025-01-19T17:47:16.000Z","updated_at":"2025-01-21T03:15:15.000Z","dependencies_parsed_at":"2025-01-21T01:26:32.141Z","dependency_job_id":"dbb787d7-23cc-465b-99fb-dedfea2ecc98","html_url":"https://github.com/imana97/MongoDB-docker-compose-cluster","commit_stats":null,"previous_names":["imana97/mongodb-sharding","imana97/mongodb-docker-compose-cluster"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imana97%2FMongoDB-docker-compose-cluster","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imana97%2FMongoDB-docker-compose-cluster/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imana97%2FMongoDB-docker-compose-cluster/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imana97%2FMongoDB-docker-compose-cluster/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/imana97","download_url":"https://codeload.github.com/imana97/MongoDB-docker-compose-cluster/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243858059,"owners_count":20359269,"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":["cluster","clustering","configserver","docker","docker-compose","mongo","router","shard"],"created_at":"2025-01-22T23:15:55.461Z","updated_at":"2026-05-07T21:36:49.056Z","avatar_url":"https://github.com/imana97.png","language":"Batchfile","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MongoDB Sharding Cluster Setup\r\n\r\nThis guide explains how to set up a MongoDB sharding cluster using Docker Compose and how to use it in a Node.js application.\r\n\r\n## Prerequisites\r\n\r\n- Docker\r\n- Docker Compose\r\n- Node.js\r\n\r\n## Setup\r\n\r\n### Step 1: Start the Docker Containers\r\n\r\nRun the following command to start the MongoDB containers:\r\n\r\n```sh\r\ndocker-compose up -d\r\n```\r\n\r\n### Step 2: Customize Docker Compose\r\n\r\nYou can customize the Docker Compose file to suit your needs. For example, you can change the memory limits, CPU limits, and volume paths.\r\n\r\n#### Example for Windows\r\n\r\n```yaml\r\nvolumes:\r\n  - F:/Database/MongoDBCluster/configs1:/data/db\r\n```\r\n\r\n#### Example for Linux\r\n\r\n```yaml\r\nvolumes:\r\n  - /mnt/f/Database/MongoDBCluster/configs1:/data/db\r\n```\r\n\r\n### Step 3: Initiate the Cluster\r\n\r\n#### For Linux/MacOS\r\n\r\nFirst, make the script executable:\r\n\r\n```sh\r\nchmod +x initiate-cluster.sh\r\n```\r\n\r\nThen, run the script:\r\n\r\n```sh\r\n./initiate-cluster.sh\r\n```\r\n\r\n#### For Windows\r\n\r\nRun the batch script:\r\n\r\n```sh\r\ninitiate-cluster.bat\r\n```\r\n\r\nThis script will set up the config server replica set, the shard replica set, and add the shard to the cluster.\r\n\r\n### Step 4: Using the Cluster in a Node.js Application\r\n\r\nTo connect to the MongoDB sharding cluster from a Node.js application, use the following connection string:\r\n\r\n```javascript\r\nconst { MongoClient } = require('mongodb');\r\n\r\nasync function main() {\r\n  const uri = \"mongodb://localhost:30000\";\r\n  const client = new MongoClient(uri);\r\n\r\n  try {\r\n    await client.connect();\r\n    console.log(\"Connected to MongoDB sharding cluster\");\r\n    // ... your application code ...\r\n  } finally {\r\n    await client.close();\r\n  }\r\n}\r\n\r\nmain().catch(console.error);\r\n```\r\n\r\nReplace `// ... your application code ...` with your actual application logic.\r\n\r\n### Step 5: Stopping the Cluster\r\n\r\nTo stop the MongoDB containers, run:\r\n\r\n```sh\r\ndocker-compose down\r\n```\r\n\r\nThis will stop and remove the containers.\r\n\r\n## Credits\r\n\r\nCredit to Iman Far (imanfar.com)\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimana97%2Fmongodb-docker-compose-cluster","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fimana97%2Fmongodb-docker-compose-cluster","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimana97%2Fmongodb-docker-compose-cluster/lists"}