Connecting to multiple IP's for replicaSet Failed

Hi MongoDB Community,

I hope you’re doing well. Apologies if this question is posted in the wrong category, but I’ve been struggling with a connectivity issue and would appreciate any assistance.

Problem:

I’m facing difficulties connecting to my MongoDB server hosted on Google Cloud Platform (GCP). I have two virtual machines (VMs) running on GCP, and MongoDB is set up and functioning on both. However, despite multiple troubleshooting attempts and trying all possible solutions, I’m still encountering the same error when attempting to connect.

Details:

  • MongoDB Setup: MongoDB is deployed on two VMs on GCP. I’ve ensured that the firewall rules are set correctly and the necessary ports (27017) are open for inbound/outbound traffic.
  • Error Message: [Include the specific error message you’re seeing here]
  • Connection Attempt: I’ve tried connecting using the correct connection string format, but it results in the error mentioned above.
  • Solutions Attempted:
    • Verified the firewall rules and network access.
    • Tested the connection with IP addresses and credentials directly from the terminal, which works, but fails when trying through the application.
    • Ensured MongoDB is listening on the correct port (27017).
    • Tried connecting via replica set configuration and direct connection string but encountered issues either way.

Questions:

  • Could there be any additional networking or security configurations I might have missed in GCP?
  • What could cause the connection to fail despite following standard practices for MongoDB deployment on GCP?
  • Is there any specific MongoDB configuration I should check for cloud-hosted instances?
  • Is there a problem with my uri mongodb://user:pass@ip1:27017,ip2:27017/db?replicaSet=myReplicaSet

Any insights or guidance on resolving this would be greatly appreciated!

Thank you for your time!