Cannot connect to MongoDB router in sharded cluster



  • I followed https://dzone.com/articles/composing-a-sharded-mongodb-on-docker on how to setup a sharded MongoDB cluster with Docker containers.

    It all seemed to work as it should because there were no error messages in the logs and the sh.status() command also gives the correct output:

    --- Sharding Status ---
      sharding version: {
            "_id" : 1,
            "minCompatibleVersion" : 5,
            "currentVersion" : 6,
            "clusterId" : ObjectId("61e566e526f7ddf44513d655")
      }
      shards:
            {  "_id" : "mongors1",  "host" : "mongors1/mongors1n1:27017,mongors1n2:27017,mongors1n3:27017",  "state" : 1,  "topologyTime" : Timestamp(1642424080, 1) }
      active mongoses:
            "5.0.2" : 2
      autosplit:
            Currently enabled: yes
      balancer:
            Currently enabled: yes
            Currently running: no
            Failed balancer rounds in last 5 attempts: 0
            Migration results for the last 24 hours:
                    No recent migrations
      databases:
            {  "_id" : "config",  "primary" : "config",  "partitioned" : true }
                    config.system.sessions
                            shard key: { "_id" : 1 }
                            unique: false
                            balancing: true
                            chunks:
                                    mongors1        1024
                            too many chunks to print, use verbose if you want to force print
            {  "_id" : "testDb",  "primary" : "mongors1",  "partitioned" : true,  "version" : {  "uuid" : UUID("31fab861-18eb-453b-9cdf-bdac1723be0c"),  "timestamp" : Timestamp(1642424142, 1),  "lastMod" : 1 } }
                    testDb.testCollection
                            shard key: { "shardingField" : 1 }
                            unique: false
                            balancing: true
                            chunks:
                                    mongors1        1
                            { "shardingField" : { "$minKey" : 1 } } -->> { "shardingField" : { "$maxKey" : 1 } } on : mongors1 Timestamp(1, 0)
    

    The routers are listening on port 27019 and 27020 but when i try to access the cluster with the Compass app I just get a timeout.

    I used this connection string: mongodb://localhost:27020,localhost:27019



  • I think I got it. I don't know why but adding --bind_ip 0.0.0.0 to each mongos process worked:

    mongos1:
        container_name: mongos1
        image: mongo
        depends_on:
          - mongocfg1
          - mongocfg2
        command: mongos --configdb mongors1conf/mongocfg1:27017,mongocfg2:27017,mongocfg3:27017 --port 27017 --bind_ip 0.0.0.0
        ports:
          - 27019:27017
        expose:
          - "27017"
    



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2