- Reference >
- Database Commands >
- Replication Commands >
- replSetReconfig
replSetReconfig¶
On this page
-
replSetReconfig
¶ The
replSetReconfig
command modifies the configuration of an existing replica set. You can use this command to add and remove members, and to alter the options set on existing members. Use the following syntax:You may also run
replSetReconfig
with the shell’srs.reconfig()
method.
Considerations¶
Be aware of the following replSetReconfig
behaviors and
considerations:
Warning
Avoid reconfiguring replica sets that contain members of different MongoDB versions as validation rules may differ across MongoDB versions.
You must issue this command against the admin database of the current primary member of the replica set.
You can optionally force the replica set to accept the new configuration by specifying
force: true
. Use this option if there is no current primary in the replica set.Warning
Forcing the
replSetReconfig
command can lead to a rollback situation. Use with caution.Use the force option to restore a replica set to new servers with different hostnames.
A majority of the set’s members must be operational for the changes to propagate properly.
This command can cause downtime as the set renegotiates primary-status. Typically this is 10-20 seconds, but could be as long as a minute or more. Therefore, you should attempt to reconfigure only during scheduled maintenance periods.
In some cases,
replSetReconfig
forces the current primary to step down, initiating an election for primary among the members of the replica set. When this happens, the primary node will drop all current connections.
Changed in version 3.2.
Non-voting members must have
priority
of 0.Before changing the
protocolVersion
, ensure that at least one oplog entry (generated from the current protocol version) has replicated from the primary to all secondaries.To verify, on each secondary, check the
optimes.lastCommittedOpTime.t
field returned fromrs.status()
. For example, connect amongo
shell to each secondary and run:- If the current replica set protocol version is
0
, thet
is equal to-1
. - If the current replica set protocol version is
1
, thet
is greater than-1
.
Once you have verified that at least one oplog entry (using the current protocol version) has replicated to all the secondaries, you can change the protocol version.
- If the current replica set protocol version is
replSetReconfig
obtains a special mutually
exclusive lock to prevent more than one
replSetReconfig
operation from occurring at the same
time.
Additional Information¶
Replica Set Configuration Fields,
Replica Set Configuration, rs.reconfig()
, and
rs.conf()
.