First of all, you can immediately distinguish the primary from a secondary from the mongo shell prompt. Otherwise, you can use the rs.status() command to determine how well (or badly!) the replica set is performing:
The rs.status() command includes some interesting sub-documents, including details on the election process, as captured here:
"electionCandidateMetrics" : {
"lastElectionReason" : "electionTimeout",
"lastElectionDate" : ISODate("2020-03-25T04:40:47.469Z"),
"electionTerm" : NumberLong(1),
...
"newTermStartDate" : ISODate("2020-03-25T04:40:48.014Z"),
"wMajorityWriteAvailabilityDate" : ISODate("2020-03-25T04:40:48.860Z")
},
You can also see detailed information on the members of the replica set. In this code block, you can see the details for the member1 server, which also happens...