How verify if replicaset is working? I am newbie with MongoDB and even more in administration of databases. But my boss passed me an issue to solve.

SCENARIO

I have two servers using MongoDB and ReplicaSet, when I run the command 

db.adminCommand( { replSetGetStatus : 1 } )


on the primary server I get the result below:

{
    ...
    "date" : ISODate("2018-12-17T10:39:00.247Z"),
    "myState" : 1,
    ...
}


and on the secondary server I get the result below:

{
    ...
    "date" : ISODate("2018-12-17T10:39:00.247Z"),
    "myState" : 2,
    ...
}


as expected.

QUESTIONS


If I stop the network interface (eth0) of the primary server to activate ReplicaSet, should the myStatus attribute of the secondary server change to 1?
If the status is to change, I have already tested it and it is not changing. How do I know that the secondary has become primary?
If I stop the network interface (eth0) of the primary server to activate ReplicaSet, should the myState attribute of the secondary server change to 1?


Since you only have two voting members in your replica set, the strict majority of voting members required to elect or maintain a primary (n/2 + 1)  is 2.

You should expect that if either member is unavailable, there will be no primary: a two member replica set does not provide automatic fault tolerance.


  If the status is to change, I have already tested it and it is not changing. How do I know that the secondary has become primary?


The replica set member state changes to reflect the current role of the replica set member. Your surviving secondary cannot become a primary without manual intervention to forcibly reconfigure the replica set. The recommended solution for production deployments is to add a third member to your replica set (ideally another data-bearing member hosted on a third machine) so your deployment can automatically recover from any single member being unavailable. 

There are several ways to confirm member state via the mongo shell:


The default mongo shell prompt is prefixed with the replica set name and member state of the MongoDB process you are connected to, for example: replset:PRIMARY&gt;. If the member state has changed, hitting &lt;enter&gt; should re-establish a connection and refresh the shell prompt.
Check via db.isMaster().primary. This status value should be set to the current host (equivalent to db.isMaster().me) if it is primary.
Check the member state in rs.status().myState. A value of 1 indicates the current member has the state PRIMARY.


You can find out more information about the election process by searching for MongoDB log lines with the  REPL log component. When you shutdown the primary on your two member replica set, you should see log messages similar to the following on your remaining secondary:

# Checking from a bash shell (note the intentional space after "REPL ")
grep "REPL " mongod.log | tail -1

2018-12-24T12:40:01.894+1100 I REPL     [replexec-2] Not starting an election, since we are not electable due to: Not standing for election because I cannot see a majority