M102 WEEK 5


Set up a replica set that includes an arbiter.

To demonstrate that you have done this, what is the value in the “state” field for the arbiter when you run rs.status()?



  1. Following steps are explained considering you have followed and completed homework from week 4.
  2. In Week4 homework, we created a replica set named as “M102”
  3. Start all three mongod servers following commands given in week4.
  4. Create a new directory 4 on same path where previous three directories were created as below
d:> mkdir 4
  1. Start another mongod server with different port having directory 4 as dbpath
> mongod --dbpath 4 --port 27004 --smallfiles --oplogSize 50 --replSet M102
  1. Run following command to start mongo shell and connect to server running on 27001 port as primary
    d:\> mongo --port 27001
  2. On shell prompt, execute following commands
> cfg = { _id : "M102", members: [ { _id : 0 , host : "Sonali:27001" } , 
 { _id : 1 , host : "Sonali:27002" } ,  { _id : 2 , host : "Sonali:27003" }, 
{ _id : 3 , host : "Sonali:27004", arbiterOnly:true }] } 
//creates  new config object
  1. We will initialize our replica set with above configuration as
> rs.initiate(cfg) // initializes replica set with given cfg object
  1. If you got error message for rs.initiate(cfg) command, try to reconfigure using below command and then check status to find your answer
> rs.reconfig(cfg) // reconfigure replica set with new cfg object
  1. Check value of “state” field for member with  value of “_id” as 3 and host name as “Sonali:27004” from output of following command.
> rs.status() // to check status of replica set
  1. Your answer is 7.


You have just been hired at a new company with an existing MongoDB deployment. They are running a single replica set with two members. When you ask why, they explain that this ensures that the data will be durable in the face of the failure of either server. They also explain that should they use a readPreference of “primaryPreferred”, that the application can read from the one remaining server during server maintenance.

You are concerned about two things, however. First, a server is brought down for maintenance once a month. When this is done, the replica set primary steps down, and the set cannot accept writes. You would like to ensure availability of writes during server maintenance.

Second, you also want to ensure that all writes can be replicated during server maintenance.

Which of the following options will allow you to ensure that a primary is available during server maintenance, and that any writes it receives will replicate during this time?

Check all that apply.

  1. Add an arbiter
  2. Add two data bearing members plus one arbiter
  3. Increase the priority of the first server from one to two.
  4. Add another data bearing node.
  5. Add two arbiters.

Answer: Yet to find answer


You would like to create a replica set that is robust to data center failure.

You only have two data centers available. Which arrangement(s) of servers will allow you to be stay up (as in, still able to elect a primary) in the event of a failure of either data center (but not both at once)? Check all that apply.

  1. All 3 servers in  data center 1.
  2. 2 servers in data center 1 and one server in data center 2.
  3. None of the above

Answer: None of the above.


Consider the following scenario: You have a two member replica set, a primary, and a secondary.

The data center with the primary goes down, and is expected to remain down for the foreseeable future. Your secondary is now the only copy of your data, and it is not accepting writes. You want to reconfigure your replica set config to exclude the primary, and allow your secondary to be elected, but you run into trouble. Find out the optional parameter that you’ll need, and input it into the box below for your rs.reconfig(new_cfg, OPTIONAL PARAMETER).

Hint: You may want to use this documentation page to solve this problem.

Your answer should be of the form { key : value } (including brackets). Do not include the rs.reconfigure portion of the query.

Answer : { force :  true }

Explanation:  You need to start all replicas so that they are reachable during configuration of replica set or you need to use “force” option.

Leave a Reply

Your email address will not be published. Required fields are marked *