First of all, make sure that the replica set is set up properly.
// In one of the replica servers mongo PRIMARY> rs.status()
In the result, you can verify the members of the set, also check the health, uptime and ping of each member.
Now let’s see the statistics for all members. When read or write is performed, we can see which member is servicing the request
In my test scenario, I have 3 nodes (2 nodes and one arbiter) and in case I lose one, I still have enough nodes to elect a new primary and have replication to a backup node.
Now simulate a case when the secondary is down
mongo SECONDARY> use admin switched to db admin SECONDARY> db.shutdownServer()
Hitting the app to check and writing data from the app still works. Yay! Failover should be automatic since mongo client knows the right set members. More here