{"id":17983000,"url":"https://github.com/minghsu0107/mongo-sharded-cluster-quickstart","last_synced_at":"2026-05-01T21:05:23.188Z","repository":{"id":144336027,"uuid":"560905040","full_name":"minghsu0107/mongo-sharded-cluster-quickstart","owner":"minghsu0107","description":"A minimal MongoDB sharded cluster using docker-compose.","archived":false,"fork":false,"pushed_at":"2022-11-02T14:28:20.000Z","size":10,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-04T02:11:26.868Z","etag":null,"topics":["docker-compose","mongodb","sharded-cluster"],"latest_commit_sha":null,"homepage":"","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/minghsu0107.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":"2022-11-02T14:22:02.000Z","updated_at":"2022-12-19T04:05:45.000Z","dependencies_parsed_at":null,"dependency_job_id":"8d9d2d8c-f94d-44a1-a622-337b19fb3264","html_url":"https://github.com/minghsu0107/mongo-sharded-cluster-quickstart","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/minghsu0107/mongo-sharded-cluster-quickstart","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/minghsu0107%2Fmongo-sharded-cluster-quickstart","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/minghsu0107%2Fmongo-sharded-cluster-quickstart/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/minghsu0107%2Fmongo-sharded-cluster-quickstart/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/minghsu0107%2Fmongo-sharded-cluster-quickstart/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/minghsu0107","download_url":"https://codeload.github.com/minghsu0107/mongo-sharded-cluster-quickstart/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/minghsu0107%2Fmongo-sharded-cluster-quickstart/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32512701,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-30T13:12:12.517Z","status":"online","status_checked_at":"2026-05-01T02:00:05.856Z","response_time":64,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["docker-compose","mongodb","sharded-cluster"],"created_at":"2024-10-29T18:15:48.422Z","updated_at":"2026-05-01T21:05:23.164Z","avatar_url":"https://github.com/minghsu0107.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MongoDB Sharded Cluster Quickstart\nSet up a minimal MongoDB sharded cluster with a replication factor of 2 using docker-compose (development only).\n\n\u003cimg src=\"https://user-images.githubusercontent.com/50090692/199514988-a81b18ee-b07c-4e12-98bf-577c98bc685a.png\" alt=\"\" width=\"600\"/\u003e\n\n### Components\n\n- Config Server (3-member replica set): `config01`,`config02`,`config03`\n- 3 Shards (each a 2 member replica set):\n\t- `shard01a`,`shard01b`\n\t- `shard02a`,`shard02b`\n\t- `shard03a`,`shard03b`\n- 1 Router (mongos): `router`\n\n### Initialization\n```bash\ndocker-compose up -d\n```\n\nInitialize the config server, shards, and router:\n```bash\nsh init.sh\n```\n\nThis script has a `sleep 20` to wait for the config server and shards to elect the primaries of their replica sets respectively before initializing the router.\n\nCreate the first user `admin` on database `admin` and verify the status of the sharded cluster:\n\n```bash\ndocker-compose exec -it router mongosh --host localhost --port 27017\nmongos\u003e admin = db.getSiblingDB(\"admin\")\nmongos\u003e admin.createUser(\n  {\n    user: \"admin\",\n    pwd:  \"mypass\",\n    roles: [ \n      { role: \"userAdminAnyDatabase\", db: \"admin\" },\n      { role: \"clusterAdmin\", db: \"admin\" }\n    ]\n  }\n)\nmongos\u003e admin.auth('admin', 'mypass')\nmongos\u003e sh.status()\nshardingVersion\n{\n  _id: 1,\n  minCompatibleVersion: 5,\n  currentVersion: 6,\n  clusterId: ObjectId(\"636276b5aabddd36d3cee9e6\")\n}\n---\nshards\n[\n  {\n    _id: 'shard01',\n    host: 'shard01/shard01a:27018,shard01b:27018',\n    state: 1,\n    topologyTime: Timestamp({ t: 1667397315, i: 4 })\n  },\n  {\n    _id: 'shard02',\n    host: 'shard02/shard02a:27019,shard02b:27019',\n    state: 1,\n    topologyTime: Timestamp({ t: 1667397315, i: 12 })\n  },\n  {\n    _id: 'shard03',\n    host: 'shard03/shard03a:27020,shard03b:27020',\n    state: 1,\n    topologyTime: Timestamp({ t: 1667397315, i: 17 })\n  }\n]\n---\nactive mongoses\n[ { '6.0.2': 1 } ]\n---\nautosplit\n{ 'Currently enabled': 'yes' }\n---\nbalancer\n{\n  'Currently enabled': 'yes',\n  'Currently running': 'no',\n  'Failed balancer rounds in last 5 attempts': 0,\n  'Migration Results for the last 24 hours': { '247': 'Success' }\n}\n---\ndatabases\n[\n  {\n    database: { _id: 'config', primary: 'config', partitioned: true },\n    collections: {\n      'config.system.sessions': {\n        shardKey: { _id: 1 },\n        unique: false,\n        balancing: true,\n        chunkMetadata: [\n          { shard: 'shard01', nChunks: 777 },\n          { shard: 'shard02', nChunks: 124 },\n          { shard: 'shard03', nChunks: 123 }\n        ],\n        chunks: [\n          'too many chunks to print, use verbose if you want to force print'\n        ],\n        tags: []\n      }\n    }\n  }\n]\n```\nTest client connection with user authentication:\n```bash\ndocker-compose exec -it router mongosh --host localhost --port 27017 -u admin -p mypass --authenticationDatabase \"admin\"\n```\nFor programming clients, you can use the following connection string URI:\n```\nmongodb://admin:mypass@router:27017/?authSource=admin\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fminghsu0107%2Fmongo-sharded-cluster-quickstart","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fminghsu0107%2Fmongo-sharded-cluster-quickstart","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fminghsu0107%2Fmongo-sharded-cluster-quickstart/lists"}