Site icon Tutorial

Remove Members from Replica Set

Remove Members from Replica Set

To remove a member of a replica set use either of the following procedures.

 Remove a Member Using rs.remove()

rs.remove(“mongod3.example.net:27017”)

rs.remove(“mongod3.example.net”)

MongoDB disconnects the shell briefly as the replica set elects a new primary. The shell then automatically reconnects. The shell displays a DBClientCursor::init call() failed error even though the command succeeds.

Remove a Member Using rs.reconfig()

To remove a member you can manually edit the replica set configuration document, as described here.

As an example, mongod_C.example.net is in position 2 of the following configuration file:

{        “_id” : “rs”,

“version” : 7,

“members” : [

{

“_id” : 0,

“host” : “mongod_A.example.net:27017”

},

{

“_id” : 1,

“host” : “mongod_B.example.net:27017”

},

{

“_id” : 2,

“host” : “mongod_C.example.net:27017”

}

]

}

{

“_id” : “rs”,

“version” : 8,

“members” : [

{   “_id” : 0,

“host” : “mongod_A.example.net:27017”

},

{  “_id” : 1,

“host” : “mongod_B.example.net:27017”

}

]

}

Apply for MongoDB Certification Now!!

https://www.vskills.in/certification/databases/mongodb-server-administrator

Back to Tutorial

Exit mobile version