Do I need to Configure replica set from MongoDB shell after server restart?

I created 2 MongoDB windows services on same server different ports as described in this website

The services will restart automatically…

My question is will i need to Configure replica set from MongoDB shell after server restart again ?

No the replicaSet configuration is statefull.

A replica set needs 3 memebers to be viable. The best is 3 data bearing replicas but a arbiter can be used(but is not advised) to create a PSA replica set.

As the primary reason for a replica set is redundancy and high availability there is very little value in placing the members on the same host.

If there are features that you want to access that rely on a replica set then a single node replica set can be configured.

1 Like

Yes you have to do it manually from shell
The document you shared clearly shows the steps
Connect to your primary port run rs.initiate() and add other node
or
While initiating itself define your nodes of your replicaset

Thanks Chris, stateful configuration makes sense… But I just want to clarify, is there anything I need to do to kick off the replication again after server reboots? for example rs.initiate again ?

unless you forgot to add them all to the service start-up list, then no.

rs.initiate writes to a configuration collection on each of those server instances, and they will know exactly what to do when they come back online. So if you don’t make dramatic changes (ports for example) to those instances, they will automatically reconnect to the set if any of them restarts for any reason.

in fact, the hard part is removing them from the set (temporary/permanent) and/or trying to make run them back as single. I exaggerated the “hard” as it may sound. so do not worry about that :slight_smile:

Thanks How, How do you remove entire replicaSet configuration ? From MongoDB Shell ?

Also I can Verify the status of all three Windows services using the sc command with query option… But i cannot connect to any of the MongoDB’s using MongoDB Compass. Any ideas ?

I figure out why i was not able to connect with MongoDB Compass… after you add “replSetName” to the cfg file you will NOT be able to connect w/ MongoDB Compass until after you configure replica set ( ie MongoDB Shell stuff )

Still wondering How do you remove entire replicaSet configuration using MongoDB Shell ?

Thanks

check the task manager if you have 3 “mongod” process. they might have stopped for you might forgot the unseen step of creating data and log folders.

  • you need 3 data folders under c:\data: db, db1 and db2
  • you need 3 log folders under C:\mongodb-win32-xxx: log, log1 and log2

f you have followed that page and did not divert from the instruction it provides, you should be able to connect them all as localhost at ports “27017”, “37017” and “47017” individually.

the primary node of your set can change at any time you restart the system, so use this to connect as a whole (connect to primary if not set otherwise):
mongodb://localhost:27017,localhost:27017,localhost:27017/?replicaSet=rs1

1 Like

for this my friend, you need a separate search. these may help

2 Likes

A replica set needs 3 memebers to be viable.

if I only have 2 members … Primary and Secondary this will not work ?

unless you set their priority levels, they will fail to decide who will be the primary. that is why 3 is the best number to break the tie. setting one of them as arbiter or hidden is also applicable. check this page:

Is there any disadvantage to using Arbiter ?

Arbiters do not hold data so cuts the storage requirements. other than having an instance of a server somewhere, no downside. just do not forget they are there to finalize voting (plus a few other functioning you don’t need for now).

No Automatic Failover when using Primary with a Secondary and an Arbiter ?

check this for more info about Replica Sets and how they behave when they lose contact with other (about failover and more)
Replication — MongoDB Manual

if primary is left alone, it will not declare itself as primary anymore. if secondary and arbiter are alive, arbiter votes for the other. more than 3 requires a bit of delicacy to get balanced decisions among alive members.

have you ever taken a course at MongoDB University? All courses are free and with proof of completion*.

I recommend you take M103 course.
M103: Basic Cluster Administration | MongoDB University

Edit: previously, I used “certificated” instead of “with proof of completion”. sorry for that.

ok, i am just trying to figure out why someone would pick Primary with a Secondary and an Arbiter over Primary with Two Secondary Members besides requiring fewer resources ?

Unless you set priorities, they will fail to assign a primary and your database will serve only as read-only. so the final decision is on who administer them and who pays for resources.

Welcome to the MongoDB Community @Alan_Tam !

Per Replica set with 3 DB Nodes and 1 Arbiter - #8 by Stennie, there are several disadvantages to using an arbiter with modern versions of MongoDB. I recommend NOT using an arbiter where possible, especially for a production deployment.

Regards,
Stennie

@Stennie just to be clear… if you had the choice between

  1. Primary Secondary Secondary
  2. Primary Secondary Arbiter

Choice would be 1 ?
can you give some disavantages w/ choice 2 ?

Thanks