I've recently followed the aws quick start cloudfront deployment for a 3 node mongo replica set.
I've set up an NLB so they are accessible from my local network and am trying to connect via mongo shell.
Trying
mongo "mongodb://<username:<password>@<url1>,<url2>,<url3>"
connects me to the database but doesn't always connect to primary so must be the incorrect way of connecting
Trying
mongo "mongodb://<username:<password>@<url1>,<url2>,<url3>/?replicaSet=s0"
I get the error Error: Could not find host matching read preference { mode: "nearest" } for set s0
The /etc/mongo.conf is
net:
port: 27017
bindIpAll: true
systemLog:
destination: file
logAppend: true
path: /log/mongod.log
storage:
dbPath: /data
journal:
enabled: true
security:
authorization: enabled
keyFile: /mongo_auth/mongodb.key
processManagement:
fork: true
pidFilePath: /var/run/mongodb/mongod.pid
replication:
replSetName: s0
And the rs.conf() is
{
"_id" : "s0",
"version" : 1,
"protocolVersion" : NumberLong(1),
"writeConcernMajorityJournalDefault" : true,
"members" : [
{
"_id" : 1,
"host" : "10.0.7.79:27017",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 10,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
},
{
"_id" : 2,
"host" : "10.0.38.224:27017",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 5,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
},
{
"_id" : 3,
"host" : "10.0.80.111:27017",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 5,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
}
],
"settings" : {
"chainingAllowed" : true,
"heartbeatIntervalMillis" : 2000,
"heartbeatTimeoutSecs" : 10,
"electionTimeoutMillis" : 10000,
"catchUpTimeoutMillis" : -1,
"catchUpTakeoverDelayMillis" : 30000,
"getLastErrorModes" : {
},
"getLastErrorDefaults" : {
"w" : 1,
"wtimeout" : 0
},
"replicaSetId" : ObjectId("myid")
}
}
The link to the quickstart guide is here
Any advice on what I might be doing wrong would be appreciated
rs.status() is
{
"set" : "s0",
"date" : ISODate("2022-01-12T19:49:16.066Z"),
"myState" : 1,
"term" : NumberLong(6),
"syncSourceHost" : "",
"syncSourceId" : -1,
"heartbeatIntervalMillis" : NumberLong(2000),
"majorityVoteCount" : 2,
"writeMajorityCount" : 2,
"votingMembersCount" : 3,
"writableVotingMembersCount" : 3,
"optimes" : {
"lastCommittedOpTime" : {
"ts" : Timestamp(1642016948, 1),
"t" : NumberLong(6)
},
"lastCommittedWallTime" : ISODate("2022-01-12T19:49:08.522Z"),
"readConcernMajorityOpTime" : {
"ts" : Timestamp(1642016948, 1),
"t" : NumberLong(6)
},
"readConcernMajorityWallTime" : ISODate("2022-01-12T19:49:08.522Z"),
"appliedOpTime" : {
"ts" : Timestamp(1642016948, 1),
"t" : NumberLong(6)
},
"durableOpTime" : {
"ts" : Timestamp(1642016948, 1),
"t" : NumberLong(6)
},
"lastAppliedWallTime" : ISODate("2022-01-12T19:49:08.522Z"),
"lastDurableWallTime" : ISODate("2022-01-12T19:49:08.522Z")
},
"lastStableRecoveryTimestamp" : Timestamp(1642016908, 1),
"electionCandidateMetrics" : {
"lastElectionReason" : "priorityTakeover",
"lastElectionDate" : ISODate("2022-01-12T13:46:38.130Z"),
"electionTerm" : NumberLong(6),
"lastCommittedOpTimeAtElection" : {
"ts" : Timestamp(1641995191, 1),
"t" : NumberLong(5)
},
"lastSeenOpTimeAtElection" : {
"ts" : Timestamp(1641995191, 1),
"t" : NumberLong(5)
},
"numVotesNeeded" : 2,
"priorityAtElection" : 10,
"electionTimeoutMillis" : NumberLong(10000),
"priorPrimaryMemberId" : 2,
"numCatchUpOps" : NumberLong(0),
"newTermStartDate" : ISODate("2022-01-12T13:46:38.137Z"),
"wMajorityWriteAvailabilityDate" : ISODate("2022-01-12T13:46:40.143Z")
},
"members" : [
{
"_id" : 1,
"name" : "10.0.7.79:27017",
"health" : 1,
"state" : 1,
"stateStr" : "PRIMARY",
"uptime" : 21770,
"optime" : {
"ts" : Timestamp(1642016948, 1),
"t" : NumberLong(6)
},
"optimeDate" : ISODate("2022-01-12T19:49:08Z"),
"lastAppliedWallTime" : ISODate("2022-01-12T19:49:08.522Z"),
"lastDurableWallTime" : ISODate("2022-01-12T19:49:08.522Z"),
"syncSourceHost" : "",
"syncSourceId" : -1,
"infoMessage" : "",
"electionTime" : Timestamp(1641995198, 1),
"electionDate" : ISODate("2022-01-12T13:46:38Z"),
"configVersion" : 1,
"configTerm" : -1,
"self" : true,
"lastHeartbeatMessage" : ""
},
{
"_id" : 2,
"name" : "10.0.38.224:27017",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 21768,
"optime" : {
"ts" : Timestamp(1642016948, 1),
"t" : NumberLong(6)
},
"optimeDurable" : {
"ts" : Timestamp(1642016948, 1),
"t" : NumberLong(6)
},
"optimeDate" : ISODate("2022-01-12T19:49:08Z"),
"optimeDurableDate" : ISODate("2022-01-12T19:49:08Z"),
"lastAppliedWallTime" : ISODate("2022-01-12T19:49:08.522Z"),
"lastDurableWallTime" : ISODate("2022-01-12T19:49:08.522Z"),
"lastHeartbeat" : ISODate("2022-01-12T19:49:14.148Z"),
"lastHeartbeatRecv" : ISODate("2022-01-12T19:49:14.507Z"),
"pingMs" : NumberLong(0),
"lastHeartbeatMessage" : "",
"syncSourceHost" : "10.0.7.79:27017",
"syncSourceId" : 1,
"infoMessage" : "",
"configVersion" : 1,
"configTerm" : -1
},
{
"_id" : 3,
"name" : "10.0.80.111:27017",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 21768,
"optime" : {
"ts" : Timestamp(1642016948, 1),
"t" : NumberLong(6)
},
"optimeDurable" : {
"ts" : Timestamp(1642016948, 1),
"t" : NumberLong(6)
},
"optimeDate" : ISODate("2022-01-12T19:49:08Z"),
"optimeDurableDate" : ISODate("2022-01-12T19:49:08Z"),
"lastAppliedWallTime" : ISODate("2022-01-12T19:49:08.522Z"),
"lastDurableWallTime" : ISODate("2022-01-12T19:49:08.522Z"),
"lastHeartbeat" : ISODate("2022-01-12T19:49:14.145Z"),
"lastHeartbeatRecv" : ISODate("2022-01-12T19:49:14.952Z"),
"pingMs" : NumberLong(0),
"lastHeartbeatMessage" : "",
"syncSourceHost" : "10.0.38.224:27017",
"syncSourceId" : 2,
"infoMessage" : "",
"configVersion" : 1,
"configTerm" : -1
}
],
"ok" : 1,
"$clusterTime" : {
"clusterTime" : Timestamp(1642016948, 1),
"signature" : {
"hash" : BinData(0,"<signature>"),
"keyId" : NumberLong("<long>")
}
},
"operationTime" : Timestamp(1642016948, 1)
}