Hi,
I’m having issues connecting to my MongoDB cluster.
I’m connecting from GCP through a serverless VPC connector with a static IP address. Previously, I was using VPC peering without any problems, but I needed a static IP, hence the change.
Sometimes I can connect without issues, but very often I cannot. Currently, the only way to resolve this is by upgrading (then downgrading) my cluster, which temporarily restores connectivity.
The error I receive is shown below. The Primary node is marked as “Unknown,” which seems to be the root cause. I’ve already tried the following troubleshooting steps:
- Verified the IP is whitelisted and static
- Changed the connection timeouts from 30 to 60 and 90 seconds without success
- Verified that DNS returns the correct IP addresses for all shards (confirmed by comparing with my local machine)
- Confirmed I can connect from my local machine without problems, suggesting it’s not an Atlas-side limit issue
{
"message": "Server selection timed out after 60000 ms",
"reason": {
"type": "ReplicaSetNoPrimary",
"servers": {
"mongo-custer-shard-00-00.p5z11.mongodb.net:27017": {
"address": "mongo-custer-shard-00-00.p5z11.mongodb.net:27017",
"type": "RSSecondary",
"hosts": [
"mongo-custer-shard-00-00.p5z11.mongodb.net:27017",
"mongo-custer-shard-00-01.p5z11.mongodb.net:27017",
"mongo-custer-shard-00-02.p5z11.mongodb.net:27017"
],
"passives": [],
"arbiters": [],
"tags": {
"provider": "GCP",
"region": "EUROPE_WEST_4",
"nodeType": "ELECTABLE",
"workloadType": "OPERATIONAL",
"availabilityZone": "europe-west4-a",
"diskState": "READY"
},
"minWireVersion": 0,
"maxWireVersion": 17,
"roundTripTime": 2.9,
"minRoundTripTime": 2,
"lastUpdateTime": 5222765,
"lastWriteDate": {
"$date": "2025-01-27T14:25:35Z"
},
"error": null,
"topologyVersion": {
"processId": {
"$oid": "6794fec901c10dfc17107655"
},
"counter": 3
},
"setName": "atlas-nk0i6g-shard-0",
"setVersion": 2,
"electionId": null,
"logicalSessionTimeoutMinutes": 30,
"maxMessageSizeBytes": 48000000,
"maxWriteBatchSize": 100000,
"maxBsonObjectSize": 16777216,
"primary": "mongo-custer-shard-00-02.p5z11.mongodb.net:27017",
"me": "mongo-custer-shard-00-00.p5z11.mongodb.net:27017",
"$clusterTime": {
"clusterTime": {
"$timestamp": {
"t": 1737987935,
"i": 2
}
},
"signature": {
"hash": {
"$binary": {
"base64": "removed",
"subType": "00"
}
},
"keyId": 7428150405197988000
}
},
"iscryptd": false
},
"mongo-custer-shard-00-01.p5z11.mongodb.net:27017": {
"address": "mongo-custer-shard-00-01.p5z11.mongodb.net:27017",
"type": "RSSecondary",
"hosts": [
"mongo-custer-shard-00-00.p5z11.mongodb.net:27017",
"mongo-custer-shard-00-01.p5z11.mongodb.net:27017",
"mongo-custer-shard-00-02.p5z11.mongodb.net:27017"
],
"passives": [],
"arbiters": [],
"tags": {
"region": "EUROPE_WEST_4",
"availabilityZone": "europe-west4-b",
"diskState": "READY",
"provider": "GCP",
"workloadType": "OPERATIONAL",
"nodeType": "ELECTABLE"
},
"minWireVersion": 0,
"maxWireVersion": 17,
"roundTripTime": 2.6,
"minRoundTripTime": 2,
"lastUpdateTime": 5222764,
"lastWriteDate": {
"$date": "2025-01-27T14:25:35Z"
},
"error": null,
"topologyVersion": {
"processId": {
"$oid": "67950166556fb57bcd11314a"
},
"counter": 3
},
"setName": "atlas-nk0i6g-shard-0",
"setVersion": 2,
"electionId": null,
"logicalSessionTimeoutMinutes": 30,
"maxMessageSizeBytes": 48000000,
"maxWriteBatchSize": 100000,
"maxBsonObjectSize": 16777216,
"primary": "mongo-custer-shard-00-02.p5z11.mongodb.net:27017",
"me": "mongo-custer-shard-00-01.p5z11.mongodb.net:27017",
"$clusterTime": {
"clusterTime": {
"$timestamp": {
"t": 1737987935,
"i": 2
}
},
"signature": {
"hash": {
"$binary": {
"base64": "removed",
"subType": "00"
}
},
"keyId": 7428150405197988000
}
},
"iscryptd": false
},
"mongo-custer-shard-00-02.p5z11.mongodb.net:27017": {
"address": "mongo-custer-shard-00-02.p5z11.mongodb.net:27017",
"type": "Unknown",
"hosts": [],
"passives": [],
"arbiters": [],
"tags": {},
"minWireVersion": 0,
"maxWireVersion": 0,
"roundTripTime": -1,
"minRoundTripTime": 0,
"lastUpdateTime": 5162976,
"lastWriteDate": 0,
"error": null,
"topologyVersion": null,
"setName": null,
"setVersion": null,
"electionId": null,
"logicalSessionTimeoutMinutes": null,
"maxMessageSizeBytes": null,
"maxWriteBatchSize": null,
"maxBsonObjectSize": null,
"primary": null,
"me": null,
"$clusterTime": null,
"iscryptd": false
}
},
"stale": false,
"compatible": true,
"heartbeatFrequencyMS": 10000,
"localThresholdMS": 15,
"setName": "atlas-nk0i6g-shard-0",
"maxElectionId": null,
"maxSetVersion": null,
"commonWireVersion": 0,
"logicalSessionTimeoutMinutes": 30
}
}