mongoDB – replica set admin cheat sheet

Connect with

In replicaset there are various types of command which you have to run for maintenance and operation point of view.

Well, first of all, let us understand what is replicaset cluster, in mongoDB. There is concept of primary-secondary or master-slave, primary/master can accept write and read but ideally you sould configured readPrefered on secondary, it means ,langurages driver sends read on secondary and write on primary. In multi deployment cluster, you can confugured read from node which is sitting near to application server. Driver is smart enouhg which identify which mongoDB node running rear to application server. There are different question in your mind like , how to convert stand alone mongdb server to replicaset? how to add node in the replicas set cluster etc.

There are diffent cheat sheet of mongoDB on as follows:

How to graceful shutdown of mongoNode?

you can put the replicaset node under maintenance by following ways.

> use admin;
> db.shutdownServer();

how to add node under replica set

> rs.add("");

how to add Arbiter node under replica set?

> rs.addArb("");

In argument , paass hostname, subdomain name, or ip of the server . Arbiter node will take participation in election to vote any one node to become primary. No data replication will be on Arbiter node.

how to remove node from replica set?

logged-in into mongodb primary node and run following.

> rs.remove("");

how to initialize mongodb nodes on replica set?

{ "_id" : "rs2",
    "version" : 1,
    "members" : [
        {"_id" : 0,"host" : "","priority" : 2},
        {"_id" : 1,"host" : "", "priority" : 1},
	{"_id" : 1,"host" : "", "priority" : 1}

here, priority is optional parameter , add this if you want to push value other than 1 , 1 is by default.
rs2 is the name of replicaset which need to set in client seed connection.

How to add hidden node in cluster?

do this off hour , not preferable in business hour

cfg.members[2].votes = 0
cfg.members[2].hidden = true;

if above not worked then do forecfully, by using folloing but don’t do this peak hour.


how to add with zero priority node

cfg.members[2]={ _id: 2, host : " 27017", priority:0 }

Here, _id should be incremental so , first check existing and then increment one for new node.

how to check long running task

> db.currentOp()

kill long running task

> db.killOp(1194053549);

Here, in argument pass process id of running job to kill.

Connect with

Leave a Reply

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