Why am I getting a login error when I try to connect to a secondary in a replica set?


When you want to connect and view data through a replica set you need to use the right read preference.

When you connect to a replica set you can either connect to the whole replica set or to a specific node.

To connect to the replica set you should list-out your nodes in the host field. For example, if your nodes are mongo0.jsonar.com, mongo1.jsonar.com and mongo2.jsonar.com all listening on the default port then enter “mongo0.jsonar.com:27017 mongo1.jsonar.com:27017 mongo2.jsonar.com:27017″ in the host field. JSON Studio will then be resilient to any node going down and will failover. If you want JSON Studio to run it’s queries on a secondary check the “prefer secondary” checkbox. JSON Studio will run queries on one of the secondaries and all writes (e.g. saved queries) will go to the primary transparently. Remember that all writes go to the Studio DB so if you want the saved queries, metadata etc to be written in another database, specify a mongodb URL in the Studio DB field.

Connecting to a specific node in the replica set directly is different depending on whether you are connecting to the primary or secondary (and in both cases your session is not resilient to failures). Usually, when you select the node to connect to directly, you will opt to use a secondary to keep load off your primary. In this case you must check the prefer secondary checkbox. Additionally, because JSON Studio cannot write any of it’s metadata to the secondary you must provide a Studio DB URL (either on this cluster or on a different cluster) to which JSON Studio can write to.


Posted in: Support