MongoDB Connectivity Issue

mongodb

From last few days, I am facing connectivity issues with MongoDB Replica Sets deployed in google cloud. Interesting fact is these issues are appeared at Development machines and not on the production. Most common issues are:

  • Cannot connect to replica set "xxx"[xxx:27017]. Set's primary is
    unreachable.
  • A primary with different host name [:27017] found in
    server side. Different members found under same replica set name
    "XXX"

These error are appeared frequently. How to resolve this?

Here is the screenshot of the error appeared:
Error connecting MongoDB

Best Answer

As per Robomongo Tool error shows like that

A primary with different host name [:27017] found in server side. Please double check if same host name and ports are used as in server's replica set configuration. If same set name is used for different replica sets, this configuration is supported only on different instances of Robomongo. Please open a new Robomongo instance for each replica set which has the same set name.

As per github blog documentation here it seems like the problem is Robomongo cannot learn the set name which is a critical information for connections to replica sets.

For Example Workaround

  1. Find a way to get your replica set name, something like rs-..., it shows it in the URL
  2. Close Robomongo
  3. Open this file in your editor
    1. ~/.config/robomongo/1.0/robomongo.json on macOS
    2. C:\Users[your name].config\robomongo.json on Windows
    3. ~/.3T/robo-3t/1.2.1/robo3t.json on Linux
  4. Search for the empty setName and add the replica set name there and save the file
  5. Start Robomongo again and it should work

For further your ref here