Getting Started
What is MongoDB?
Install / Config
C.R.U.D. Ops
Data Modeling
Database Mgmt
MongoDB Database Management
Configuring a Replica Set: Reconfiguring or Removing
How do you set "primary" or "secondary"?
.
An up-to-date MongoDB instance with the
highest
priority
setting will become the Primary
How do you use
rs.reconfig()
to set the priority?
.
View config:
rs.conf()
Make a note of the
_id
number under members
Assign config to a variable:
config = rs.conf()
Set the priority:
config.members[X].priority=N
Where
X
is the member _id to change
and where
N
is the priority number
Reconfigure:
rs.reconfig(config)
How else can you use
rs.reconfig()
?
.
Remove replica set members
Rename DNS or hostnames
What has to be done before removing a member?
.
Stop MongoDB on the replica set member to be removed
Disable the
replSet
setting in the mongod.conf file
How do you use
rs.remove()
?
.
Connect to the Primary
Use
db.isMaster()
to ensure the replica member is the Primary
Type:
rs.remove("dns.address|hostname")
Or:
rs.remove("dns.address|hostname:port")
How do you force a member to become primary?
.
From the mongo shell of the current primary:
rs.stepDown(120)
From the mongo shell of the undesired secondaries:
rs.freeze(120)
The remaining secondary will become primary
Alternatively:
use local
db.system.replset.update({_id:"rs0"},{$set:{members:[{_id:0,host:"HOSTNAME:27017"}]}})
+
o
-