OK so, I have a multipass vm running on an M1 mac. It's hosting an ubuntu server. On this ubuntu server I've installed go, gin, and a bunch of other related technologies. I then get to mongo.
I first create the replication set with sudo docker network create mongoCluster
Then I spin up three nodes:
sudo docker run -d -p 27017:27017 --name mongo1 --network mongoCluster -e MONGODB_INITDB_ROOT_USERNAME=myuser -e MONGODB_INITDB_ROOT_PASSWORD=mypassword -e MONGO_INITDB_DATABASE=task mongo:latest mongod --replSet myReplicaSet --bind_ip localhost,mongo1
sudo docker run -d -p 27018:27017 --name mongo2 --network mongoCluster mongo:latest mongod --replSet myReplicaSet --bind_ip localhost,mongo2
sudo docker run -d -p 27019:27017 --name mongo3 --network mongoCluster mongo:latest mongod --replSet myReplicaSet --bind_ip localhost,mongo3
Then I initialize the replication set with
sudo docker exec -it mongo1 mongosh --eval "rs.initiate({
_id: \"myReplicaSet\",
members: [
{_id: 0, host: \"mongo1\"},
{_id: 1, host: \"mongo2\"},
{_id: 2, host: \"mongo3\"}
]
})"
running sudo docker exec -it mongo2 mongosh --eval "rs.status()" shows me it's all set up correctly with mongo1 as the PRIMARY
So far so good!
Then I fire up my app and make the connection with the uri: mongodb://myuser:mypassword@localhost:27017/?retryWrites=true&w=majority
Mongo throws an error Failed to ping cluster, but it then reports that it connected
Then it throws this:
Could not create Task: server selection error: context deadline exceeded, current topology: { Type: ReplicaSetNoPrimary, Servers: [{ Addr: mongo1:27017, Type: Unknown, Last error: connection() error occurred during connection handshake: dial tcp: lookup mongo1: Temporary failure in name resolution }, { Addr: mongo2:27017, Type: Unknown, Last error: connection() error occurred during connection handshake: dial tcp: lookup mongo2: Temporary failure in name resolution }, { Addr: mongo3:27017, Type: Unknown, Last error: connection() error occurred during connection handshake: dial tcp: lookup mongo3: Temporary failure in name resolution }, ] }
So it looks like the various nodes can't see each other I've been searching the googs for a while, but nothing seems to address my specific issue
I even put the money down on a training course to figure this out, but haven't. Please help!