monstache: server selection error: server selection timeout
$ monstache:
ERROR 2019/11/15 03:35:16 Unable to connect to MongoDB using URL mongodb://localhost:27017: server selection error: server selection timeout
current topology: Type: ReplicaSetNoPrimary
Servers:
Addr: <hostname>:27017, Type: Unknown, State: Connected, Average RTT: 0, Last error: connection(<hostname>:27017[-360]) connection is closed
Addr: <hostname>:27018, Type: Unknown, State: Connected, Average RTT: 0, Last error: connection(<hostname>:27018[-361]) connection is closed
Addr: <hostname>:27019, Type: Unknown, State: Connected, Average RTT: 0, Last error: connection(<hostname>:27019[-362]) connection is closed
rs.status():
{
"set" : "rs0",
"date" : ISODate("2019-11-15T11:34:24.146Z"),
"myState" : 1,
"term" : NumberLong(6),
"syncingTo" : "",
"syncSourceHost" : "",
"syncSourceId" : -1,
"heartbeatIntervalMillis" : NumberLong(2000),
"majorityVoteCount" : 2,
"writeMajorityCount" : 2,
"optimes" : {
"lastCommittedOpTime" : {
"ts" : Timestamp(1573817656, 1),
"t" : NumberLong(6)
},
"lastCommittedWallTime" : ISODate("2019-11-15T11:34:16.581Z"),
"readConcernMajorityOpTime" : {
"ts" : Timestamp(1573817656, 1),
"t" : NumberLong(6)
},
"readConcernMajorityWallTime" : ISODate("2019-11-15T11:34:16.581Z"),
"appliedOpTime" : {
"ts" : Timestamp(1573817656, 1),
"t" : NumberLong(6)
},
"durableOpTime" : {
"ts" : Timestamp(1573817656, 1),
"t" : NumberLong(6)
},
"lastAppliedWallTime" : ISODate("2019-11-15T11:34:16.581Z"),
"lastDurableWallTime" : ISODate("2019-11-15T11:34:16.581Z")
},
"lastStableRecoveryTimestamp" : Timestamp(1573817636, 1),
"lastStableCheckpointTimestamp" : Timestamp(1573817636, 1),
"electionCandidateMetrics" : {
"lastElectionReason" : "priorityTakeover",
"lastElectionDate" : ISODate("2019-11-15T11:33:36.195Z"),
"termAtElection" : NumberLong(6),
"lastCommittedOpTimeAtElection" : {
"ts" : Timestamp(1573817606, 1),
"t" : NumberLong(5)
},
"lastSeenOpTimeAtElection" : {
"ts" : Timestamp(1573817606, 1),
"t" : NumberLong(5)
},
"numVotesNeeded" : 2,
"priorityAtElection" : 1,
"electionTimeoutMillis" : NumberLong(10000),
"priorPrimaryMemberId" : 2,
"numCatchUpOps" : NumberLong(1375993858),
"newTermStartDate" : ISODate("2019-11-15T11:33:36.575Z"),
"wMajorityWriteAvailabilityDate" : ISODate("2019-11-15T11:33:37.722Z")
},
"members" : [
{
"_id" : 0,
"name" : "<hostname>:27017",
"ip" : "127.0.0.1",
"health" : 1,
"state" : 1,
"stateStr" : "PRIMARY",
"uptime" : 79,
"optime" : {
"ts" : Timestamp(1573817656, 1),
"t" : NumberLong(6)
},
"optimeDate" : ISODate("2019-11-15T11:34:16Z"),
"syncingTo" : "",
"syncSourceHost" : "",
"syncSourceId" : -1,
"infoMessage" : "",
"electionTime" : Timestamp(1573817616, 1),
"electionDate" : ISODate("2019-11-15T11:33:36Z"),
"configVersion" : 2,
"self" : true,
"lastHeartbeatMessage" : ""
},
{
"_id" : 1,
"name" : "<hostname>:27018",
"ip" : "127.0.0.1",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 62,
"optime" : {
"ts" : Timestamp(1573817656, 1),
"t" : NumberLong(6)
},
"optimeDurable" : {
"ts" : Timestamp(1573817656, 1),
"t" : NumberLong(6)
},
"optimeDate" : ISODate("2019-11-15T11:34:16Z"),
"optimeDurableDate" : ISODate("2019-11-15T11:34:16Z"),
"lastHeartbeat" : ISODate("2019-11-15T11:34:22.253Z"),
"lastHeartbeatRecv" : ISODate("2019-11-15T11:34:23.758Z"),
"pingMs" : NumberLong(0),
"lastHeartbeatMessage" : "",
"syncingTo" : "<hostname>:27017",
"syncSourceHost" : "<hostname>:27017",
"syncSourceId" : 0,
"infoMessage" : "",
"configVersion" : 2
},
{
"_id" : 2,
"name" : "<hostname>:27019",
"ip" : "127.0.0.1",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 68,
"optime" : {
"ts" : Timestamp(1573817656, 1),
"t" : NumberLong(6)
},
"optimeDurable" : {
"ts" : Timestamp(1573817656, 1),
"t" : NumberLong(6)
},
"optimeDate" : ISODate("2019-11-15T11:34:16Z"),
"optimeDurableDate" : ISODate("2019-11-15T11:34:16Z"),
"lastHeartbeat" : ISODate("2019-11-15T11:34:22.253Z"),
"lastHeartbeatRecv" : ISODate("2019-11-15T11:34:22.392Z"),
"pingMs" : NumberLong(0),
"lastHeartbeatMessage" : "",
"syncingTo" : "<hostname>:27018",
"syncSourceHost" : "<hostname>:27018",
"syncSourceId" : 1,
"infoMessage" : "",
"configVersion" : 2
}
],
"ok" : 1,
"$clusterTime" : {
"clusterTime" : Timestamp(1573817656, 1),
"signature" : {
"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
"keyId" : NumberLong(0)
}
},
"operationTime" : Timestamp(1573817656, 1)
}
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 19 (6 by maintainers)
Have you tried connecting with the hostname set to the value of <hostname> in your
rs.status()output instead of using localhost?Adding
?connect=directmay fix it but I’ve not needed to use that.I faced exactly the same error message when trying to connect to AWS DocumentDB but could not resolve it with adding ‘connect=direct’. Instead it turned out i had forgotten to add the certificates to the connectionstring. The following worked for me: mongodb://…docdb.amazonaws.com:27017/test?tlsCAFile=/app/rds-ca-2019-root.pem
Oh, I hava solve it by add param ‘connect=direct’. Sorry to bother you!