Awesome then the next thing is to check network connectivity from your GCP vm to all replica set members. you can do that by using something like telnet:
telnet <node1-ip> 27017
telnet <node1-ip> 27017
telnet <node1-ip> 27017
from that i think you may see that the issue is that the hostname cannot be resolved from your gcp vm. (this is usually the issue).
from the original command that i posted rs.conf shouldve shown entries like:
host: mongodb1:27017
host: mongodb2:27017
so to fix you can either:
option1: add hostname mappings to /etc/hosts on your GCP vm
<node1-ip> mongodb1
<node2-ip> mongodb2
<node3-ip> mongodb3
option2: reconfigure the replica set with ip addresses
cfg = rs.conf()
cfg.members[0].host = "<node1-ip>:27017"
cfg.members[1].host = "<node2-ip>:27017"
cfg.members[2].host = "<node3-ip>:27017"
rs.reconfig(cfg)
important:
port 27017 should be open between all nodes and the vm:
- gcp vm and all mongo nodes (so your vm can connect)
- all mongo nodes with each other (so they can work together)