Flipping from Primary to Secondary after adding replication sets

This is a lot fun but I am struggling…

I am able to add my replication sets when doing the x509 replication set exercise but when I do the rs.status - I become a SECONDARY.

I add the two sets below:

MongoDB Enterprise myReplSet:PRIMARY> rs.add(“database.m310.mongodb.university:31131”)
{ “ok” : 1 }
MongoDB Enterprise myReplSet:PRIMARY> rs.add(“database.m310.mongodb.university:31132”)
{ “ok” : 1 }

Then when I go to check the status:

MongoDB Enterprise myReplSet:PRIMARY> rs.status()

I get:

2019-02-17T18:42:19.554+0000 E QUERY [thread1] Error: error doing query: failed: network error while attempting to run command ‘replSetGetStatus’ on host ‘database.m310.mongodb.university:31130’ :
DB.prototype.runCommand@src/mongo/shell/db.js:135:1
DB.prototype.adminCommand@src/mongo/shell/db.js:152:1
rs.status@src/mongo/shell/utils.js:1111:12
@(shell):1:1

2019-02-17T18:42:19.556+0000 I NETWORK [thread1] trying reconnect to database.m310.mongodb.university:31130 (127.0.1.1) failed
2019-02-17T18:42:19.584+0000 I NETWORK [thread1] reconnect database.m310.mongodb.university:31130 (127.0.1.1) ok

And then I am marked as SECONDARY,

MongoDB Enterprise myReplSet:SECONDARY>

Any guidance?

Solved it by initiating with replica set parameters within rs.initiate ( ).

@ Ted_63853

First of all, run rs.status() again and see which of your members is now PRIMARY. It may be that you simply have one member that is not yet fully integrated into the rs, in which case it’s likely that your 31130 system will return to PRIMARY status.

However, from the messages it looks like you may have lost contact briefly with the old PRIMARY (31130) so there was an election and now the system you’re on is SECONDARY. To switch 31130 back to primary follow the instructions here in the section “Force a Member to be Primary Using Database Commands”.

By listing the instances inside rs.instantiate it worked out fine. Thank you.