Connection from app client


I think that I am understanding every, but I have a question yet. When I share a link for my developer connect in a replicaSet, how I pass one IP/Domain to him. If this node down, he doesn’t connect in mongo replicaset, right? How I can prevent this scene?

Hi raragao,

I am unable to understand your question.

  • If you are asking that you have one replica set running, how would you pass IP/domain to him?
    – You can provide the IP like we did from atlas, we created a cluster on atlas and unless and until it’s running, the developer will be able to connect.
    – If one node goes down, then also he has connection parameters for replicaSet, if one node goes down, other node becomes primary after election and he will be able to retrieve data through that node.
    – If one node goes down and he has not connected to the replicaSet instead just one particular node, then he needs to disconnect and connect to other node himself.

For more information, please refer mongodb documentation.


My question is based in this cluster replicaset example:

Node1: (primary)

How my app can connect to be resilient if primary node down?

There is always an interchange of heartbeats between the nodes of a replica set. So, if the other nodes did not receive heartbeat from one nodes say 27001, then it means primary 27001 is down.

In this case its 27001, then there will be an election between 27002 and 27003. After the election, primary will be decided and your application should be still running.

For example: in vagrant m103:

start 3 node -replica set 27001, 27002 and 27003. Connect using:

  mongo --host m103-repl/localhost:27001,localhost:27002,localhost:27003

Then shutdown 27001 node using kill command followed by ps -ef | grep mongod

Then try to connect to the same replica set, you will see below message until the election is done.

      Unable to reach primary for set m103-repl

Then you will automatically be connected to the new primary and thats how we ensure the connection in your application.


You don’t connect to the primary, you connect to the replica set, it will route you to which ever node is the primary at that time.

You specify the replica set name as part of your connection.

Connecting to the replica set (remove the m103-example replica set name) from the connection string to connect to a specific node:

mongo --host "m103-example/" -u "m103-admin" -p
"m103-pass" --authenticationDatabase "admin"

Connecting directly to a specific secondary node:

mongo --host "" -u "m103-admin" -p "m103-pass"
–authenticationDatabase "admin"

Assuming you are connecting to a test database from the course.

1 Like

Hi @Kanika, great. Then my app should to connect to all nodes that are eligible as primary ?

@NMullins, thank you. But my ask is exactly when host that you connect is down. I know that we connect to replicaset, but this connection is did by a IP:PORT, and if this IP:PORT is down I didn’t want change my app string connection to this.

Yes, that’s right.


1 Like