When i am trying run using the docker-compose.yml version 5.0.24 and I am doing all this in a ec2 server AWS
version: "3.0" # Update the version to "3.0" as per your requirement
volumes:
db-mongo-keys26:
db-mongo-data-26:
db-mongo-data-27:
db-mongo-data-28:
networks:
db-cluster26:
driver: bridge
ipam:
driver: default
config:
- subnet: 162.10.21.0/24
services:
db-mongo-keys26:
image: depop/openssl-bats
volumes:
- db-mongo-keys26:/mongo-conf
command: 'bash -c "openssl rand -base64 741 > /mongo-conf/mongodb-keyfile; chmod 600 /mongo-conf/mongodb-keyfile; chown 999 /mongo-conf/mongodb-keyfile"'
# Node1
db-mongo-node17:
container_name: db-mongo-node17
image: mongo:5.0.24 # Update the MongoDB version to "5.0.24"
volumes:
- db-mongo-keys26:/opt/keyfile
- db-mongo-data-26:/data/db
env_file:
./mongod.env
ports:
- 27017:27017 # Change the host port to 27017
command: 'mongod --auth --keyFile /opt/keyfile/mongodb-keyfile --replSet db-ppd'
depends_on:
- db-mongo-keys26
networks:
db-cluster26:
# Node2
db-mongo-node18:
container_name: db-mongo-node18
image: mongo:5.0.24
volumes:
- db-mongo-keys26:/opt/keyfile
- db-mongo-data-27:/data/db
env_file:
./mongod.env
ports:
- 27018:27017 # Change the host port to 27018
command: 'mongod --auth --keyFile /opt/keyfile/mongodb-keyfile --replSet db-ppd'
depends_on:
- db-mongo-keys26
networks:
db-cluster26:
# Node3
db-mongo-node19:
container_name: db-mongo-node19
image: mongo:5.0.24
volumes:
- db-mongo-keys26:/opt/keyfile
- db-mongo-data-28:/data/db
env_file:
./mongod.env
ports:
- 27019:27017 # Change the host port to 27019
command: 'mongod --auth --keyFile /opt/keyfile/mongodb-keyfile --replSet db-ppd'
depends_on:
- db-mongo-keys26
networks:
db-cluster26:
rs.initiate({
_id: "db-ppd",
members: [
{_id: 0, host: "db-mongo-node17:27017"},
{_id: 1, host: "db-mongo-node18:27017"},
{_id: 2, host: "db-mongo-node19:27017"}
]
})
And i have created a root user and trying to connect into my mongodb compass like this and this doesn't work it give an error - getaddrinfo ENOTFOUND db-mongo-node17 mongodb://root:*****@host_address:27017,host_address:27018,host_address:27018/?replicaSet=db-ppd
db-ppd:PRIMARY> rs.status()
{
"set" : "db-ppd",
"date" : ISODate("2024-02-26T12:55:41.236Z"),
"myState" : 1,
"term" : NumberLong(8),
"syncSourceHost" : "",
"syncSourceId" : -1,
"heartbeatIntervalMillis" : NumberLong(2000),
"majorityVoteCount" : 2,
"writeMajorityCount" : 2,
"votingMembersCount" : 3,
"writableVotingMembersCount" : 3,
"optimes" : {
"lastCommittedOpTime" : {
"ts" : Timestamp(1708952138, 1),
"t" : NumberLong(8)
},
"lastCommittedWallTime" : ISODate("2024-02-26T12:55:38.624Z"),
"readConcernMajorityOpTime" : {
"ts" : Timestamp(1708952138, 1),
"t" : NumberLong(8)
},
"appliedOpTime" : {
"ts" : Timestamp(1708952138, 1),
"t" : NumberLong(8)
},
"durableOpTime" : {
"ts" : Timestamp(1708952138, 1),
"t" : NumberLong(8)
},
"lastAppliedWallTime" : ISODate("2024-02-26T12:55:38.624Z"),
"lastDurableWallTime" : ISODate("2024-02-26T12:55:38.624Z")
},
"lastStableRecoveryTimestamp" : Timestamp(1708952118, 1),
"electionCandidateMetrics" : {
"lastElectionReason" : "electionTimeout",
"lastElectionDate" : ISODate("2024-02-26T11:41:28.430Z"),
"electionTerm" : NumberLong(8),
"lastCommittedOpTimeAtElection" : {
"ts" : Timestamp(0, 0),
"t" : NumberLong(-1)
},
"lastSeenOpTimeAtElection" : {
"ts" : Timestamp(1708947657, 1),
"t" : NumberLong(6)
},
"numVotesNeeded" : 2,
"priorityAtElection" : 1,
"electionTimeoutMillis" : NumberLong(10000),
"numCatchUpOps" : NumberLong(0),
"newTermStartDate" : ISODate("2024-02-26T11:41:28.443Z"),
"wMajorityWriteAvailabilityDate" : ISODate("2024-02-26T11:41:28.752Z")
},
"members" : [
{
"_id" : 0,
"name" : "db-mongo-node17:27017",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 4463,
"optime" : {
"ts" : Timestamp(1708952138, 1),
"t" : NumberLong(8)
},
"optimeDurable" : {
"ts" : Timestamp(1708952138, 1),
"t" : NumberLong(8)
},
"optimeDate" : ISODate("2024-02-26T12:55:38Z"),
"optimeDurableDate" : ISODate("2024-02-26T12:55:38Z"),
"lastAppliedWallTime" : ISODate("2024-02-26T12:55:38.624Z"),
"lastDurableWallTime" : ISODate("2024-02-26T12:55:38.624Z"),
"lastHeartbeat" : ISODate("2024-02-26T12:55:40.928Z"),
"lastHeartbeatRecv" : ISODate("2024-02-26T12:55:39.567Z"),
"pingMs" : NumberLong(0),
"lastHeartbeatMessage" : "",
"syncSourceHost" : "db-mongo-node19:27017",
"syncSourceId" : 2,
"infoMessage" : "",
"configVersion" : 1,
"configTerm" : 8
},
{
"_id" : 1,
"name" : "db-mongo-node18:27017",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 4462,
"optime" : {
"ts" : Timestamp(1708952138, 1),
"t" : NumberLong(8)
},
"optimeDurable" : {
"ts" : Timestamp(1708952138, 1),
"t" : NumberLong(8)
},
"optimeDate" : ISODate("2024-02-26T12:55:38Z"),
"optimeDurableDate" : ISODate("2024-02-26T12:55:38Z"),
"lastAppliedWallTime" : ISODate("2024-02-26T12:55:38.624Z"),
"lastDurableWallTime" : ISODate("2024-02-26T12:55:38.624Z"),
"lastHeartbeat" : ISODate("2024-02-26T12:55:40.929Z"),
"lastHeartbeatRecv" : ISODate("2024-02-26T12:55:39.956Z"),
"pingMs" : NumberLong(0),
"lastHeartbeatMessage" : "",
"syncSourceHost" : "db-mongo-node19:27017",
"syncSourceId" : 2,
"infoMessage" : "",
"configVersion" : 1,
"configTerm" : 8
},
{
"_id" : 2,
"name" : "db-mongo-node19:27017",
"health" : 1,
"state" : 1,
"stateStr" : "PRIMARY",
"uptime" : 4465,
"optime" : {
"ts" : Timestamp(1708952138, 1),
"t" : NumberLong(8)
},
"optimeDate" : ISODate("2024-02-26T12:55:38Z"),
"lastAppliedWallTime" : ISODate("2024-02-26T12:55:38.624Z"),
"lastDurableWallTime" : ISODate("2024-02-26T12:55:38.624Z"),
"syncSourceHost" : "",
"syncSourceId" : -1,
"infoMessage" : "",
"electionTime" : Timestamp(1708947688, 1),
"electionDate" : ISODate("2024-02-26T11:41:28Z"),
"configVersion" : 1,
"configTerm" : 8,
"self" : true,
"lastHeartbeatMessage" : ""
}
],
"ok" : 1,
"$clusterTime" : {
"clusterTime" : Timestamp(1708952138, 1),
"signature" : {
"hash" : BinData(0,"zl2L6hBW70Cr5140qnwfseqG0fA="),
"keyId" : NumberLong("7339807892901462020")
}
},
"operationTime" : Timestamp(1708952138, 1)
}
When i am trying run using the docker-compose.yml version 5.0.24 and I am doing all this in a ec2 server AWS
This is to initiate the replica set
And i have created a root user and trying to connect into my mongodb compass like this and this doesn't work it give an error -
getaddrinfo ENOTFOUND db-mongo-node17 mongodb://root:*****@host_address:27017,host_address:27018,host_address:27018/?replicaSet=db-ppdBut when i try like this - it show me the db and work fine
mongodb://root:root@host_address:27017/?directConnection=trueI have no idea why this doesn't work when i don't try with the direct connection
If you need the rs.status , if it helps here it is
If anyone can help, it will be very much appreciated