Skip to content

unable to connect using replicas uri #418

@bwgjoseph

Description

@bwgjoseph

Hi,

I'm trying to setup mongo-replicas setup using docker-compose. Here's my script

click to show
version: '3.7'

services:
  mongo-primary:
    image: mongo:4.4.0
    container_name: mongo-primary
    ports:
      - 30000:27017
    networks:
      - mongo_db_network
    volumes:
      - mongo_db_primary:/data/db
      - mongo_configdb_primary:/data/configdb
    restart: unless-stopped
    depends_on:
      - mongo-secondary
      - mongo-arbiter
    command: "--bind_ip_all --replSet rs0"

  mongo-secondary:
    image: mongo:4.4.0
    container_name: mongo-secondary
    ports:
      - 30001:27017
    networks:
      - mongo_db_network
    volumes:
      - mongo_db_secondary:/data/db
      - mongo_configdb_secondary:/data/configdb
    restart: unless-stopped
    command: "--bind_ip_all --replSet rs0"

  mongo-arbiter:
    image: mongo:4.4.0
    container_name: mongo-arbiter
    ports:
      - 30002:27017
    networks:
      - mongo_db_network
    volumes:
      - mongo_db_arbiter:/data/db
      - mongo_configdb_arbiter:/data/configdb
    restart: unless-stopped
    command: "--bind_ip_all --replSet rs0"

  mongo-setup:
    image: mongo:4.4.0
    container_name: mongo-setup
    volumes:
      - ./scripts:/scripts
    networks:
      - mongo_db_network
    depends_on:
      - mongo-primary
      - mongo-secondary
      - mongo-arbiter
    entrypoint: [ "/scripts/setup.sh" ]
    restart: on-failure

  mongo-replicas-express:
    image: mongo-express:0.54.0
    container_name: mongo-replicas-express
    ports:
      - 38081:8081
    networks:
      - mongo_db_network
    depends_on:
      - mongo-primary
    environment:
      ME_CONFIG_MONGODB_SERVER: mongo-primary,mongo-secondary,mongo-arbiter
      ME_CONFIG_MONGODB_ADMINUSERNAME: root
      ME_CONFIG_MONGODB_ADMINPASSWORD: password
    restart: unless-stopped

volumes:
    mongo_db_primary:
    mongo_configdb_primary:
    mongo_db_secondary:
    mongo_configdb_secondary:
    mongo_db_arbiter:
    mongo_configdb_arbiter:

networks:
  mongo_db_network:

This is my rs.status() when I run the command in mongo-primary

click to show
rs0:PRIMARY> rs.status()
{
        "set" : "rs0",
        "date" : ISODate("2020-08-29T14:12:17.005Z"),
        "myState" : 1,
        "term" : NumberLong(10),
        "syncSourceHost" : "",
        "syncSourceId" : -1,
        "heartbeatIntervalMillis" : NumberLong(2000),
        "majorityVoteCount" : 2,
        "writeMajorityCount" : 2,
        "votingMembersCount" : 3,
        "writableVotingMembersCount" : 2,
        "optimes" : {
                "lastCommittedOpTime" : {
                        "ts" : Timestamp(1598710328, 1),
                        "t" : NumberLong(10)
                },
                "lastCommittedWallTime" : ISODate("2020-08-29T14:12:08.975Z"),
                "readConcernMajorityOpTime" : {
                        "ts" : Timestamp(1598710328, 1),
                        "t" : NumberLong(10)
                },
                "readConcernMajorityWallTime" : ISODate("2020-08-29T14:12:08.975Z"),
                "appliedOpTime" : {
                        "ts" : Timestamp(1598710328, 1),
                        "t" : NumberLong(10)
                },
                "durableOpTime" : {
                        "ts" : Timestamp(1598710328, 1),
                        "t" : NumberLong(10)
                },
                "lastAppliedWallTime" : ISODate("2020-08-29T14:12:08.975Z"),
                "lastDurableWallTime" : ISODate("2020-08-29T14:12:08.975Z")
        },
        "lastStableRecoveryTimestamp" : Timestamp(1598710308, 1),
        "electionCandidateMetrics" : {
                "lastElectionReason" : "priorityTakeover",
                "lastElectionDate" : ISODate("2020-08-29T13:53:08.904Z"),
                "electionTerm" : NumberLong(10),
                "lastCommittedOpTimeAtElection" : {
                        "ts" : Timestamp(1598709178, 2),
                        "t" : NumberLong(9)
                },
                "lastSeenOpTimeAtElection" : {
                        "ts" : Timestamp(1598709188, 1),
                        "t" : NumberLong(9)
                },
                "numVotesNeeded" : 2,
                "priorityAtElection" : 2,
                "electionTimeoutMillis" : NumberLong(10000),
                "priorPrimaryMemberId" : 1,
                "numCatchUpOps" : NumberLong(0),
                "newTermStartDate" : ISODate("2020-08-29T13:53:08.924Z"),
                "wMajorityWriteAvailabilityDate" : ISODate("2020-08-29T13:53:09.932Z")
        },
        "electionParticipantMetrics" : {
                "votedForCandidate" : true,
                "electionTerm" : NumberLong(9),
                "lastVoteDate" : ISODate("2020-08-29T13:52:58.834Z"),
                "electionCandidateMemberId" : 1,
                "voteReason" : "",
                "lastAppliedOpTimeAtElection" : {
                        "ts" : Timestamp(1598709096, 1),
                        "t" : NumberLong(8)
                },
                "maxAppliedOpTimeInSet" : {
                        "ts" : Timestamp(1598709096, 1),
                        "t" : NumberLong(8)
                },
                "priorityAtElection" : 2
        },
        "members" : [
                {
                        "_id" : 0,
                        "name" : "mongo-primary:27017",
                        "health" : 1,
                        "state" : 1,
                        "stateStr" : "PRIMARY",
                        "uptime" : 1171,
                        "optime" : {
                                "ts" : Timestamp(1598710328, 1),
                                "t" : NumberLong(10)
                        },
                        "optimeDate" : ISODate("2020-08-29T14:12:08Z"),
                        "syncSourceHost" : "",
                        "syncSourceId" : -1,
                        "infoMessage" : "",
                        "electionTime" : Timestamp(1598709188, 2),
                        "electionDate" : ISODate("2020-08-29T13:53:08Z"),
                        "configVersion" : 1,
                        "configTerm" : 10,
                        "self" : true,
                        "lastHeartbeatMessage" : ""
                },
                {
                        "_id" : 1,
                        "name" : "mongo-secondary:27017",
                        "health" : 1,
                        "state" : 2,
                        "stateStr" : "SECONDARY",
                        "uptime" : 1168,
                        "optime" : {
                                "ts" : Timestamp(1598710328, 1),
                                "t" : NumberLong(10)
                        },
                        "optimeDurable" : {
                                "ts" : Timestamp(1598710328, 1),
                                "t" : NumberLong(10)
                        },
                        "optimeDate" : ISODate("2020-08-29T14:12:08Z"),
                        "optimeDurableDate" : ISODate("2020-08-29T14:12:08Z"),
                        "lastHeartbeat" : ISODate("2020-08-29T14:12:15.140Z"),
                        "lastHeartbeatRecv" : ISODate("2020-08-29T14:12:16.194Z"),
                        "pingMs" : NumberLong(0),
                        "lastHeartbeatMessage" : "",
                        "syncSourceHost" : "mongo-primary:27017",
                        "syncSourceId" : 0,
                        "infoMessage" : "",
                        "configVersion" : 1,
                        "configTerm" : 10
                },
                {
                        "_id" : 2,
                        "name" : "mongo-arbiter:27017",
                        "health" : 1,
                        "state" : 7,
                        "stateStr" : "ARBITER",
                        "uptime" : 1168,
                        "lastHeartbeat" : ISODate("2020-08-29T14:12:15.106Z"),
                        "lastHeartbeatRecv" : ISODate("2020-08-29T14:12:15.106Z"),
                        "pingMs" : NumberLong(0),
                        "lastHeartbeatMessage" : "",
                        "syncSourceHost" : "",
                        "syncSourceId" : -1,
                        "infoMessage" : "",
                        "configVersion" : 1,
                        "configTerm" : 10
                }
        ],
        "ok" : 1,
        "$clusterTime" : {
                "clusterTime" : Timestamp(1598710328, 1),
                "signature" : {
                        "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
                        "keyId" : NumberLong(0)
                }
        },
        "operationTime" : Timestamp(1598710328, 1)
}

I can access mongo-express

image


I can connect via mongo3t using the following directly to 30000, or 30001

image

When I connect programmatically through my app using mongoose via mongodb://localhost:30000/ttt uri, I have no issue.


The problem comes when I try to connect using mongodb://localhost:30000,localhost:30001,localhost:30002/ttt?replicaSet=rs0, it will complain this.

[2020-08-29 22:29:44] [error] Could not connect to any servers in your MongoDB Atlas cluster. One common reason is that you're trying to access the database from an IP that isn't whitelisted. Make sure your current IP address is on your Atlas cluster's IP whitelist: https://docs.atlas.mongodb.com/security-whitelist/
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! elendarth@0.1.0 dev: `ts-node-dev --no-notify src/`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the elendarth@0.1.0 dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Joseph\AppData\Roaming\npm-cache\_logs\2020-08-29T14_29_44_686Z-debug.log

I'm not sure why it is complaining about the MongoDB Atlas cluster though. I'm running this locally on my machine using docker

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions