Database Reference
In-Depth Information
Table 11-2. Commands for Manipulating and Inspecting Replica Sets
Command
Description
rs.help()
Returns the list of the commands in this table.
rs.status()
Returns information about the current state of the replica set. This command lists
each member server, along with information about its status, including the last
time it was contacted. This call can be used to provide a simple health check of the
entire cluster.
rs.initiate()
Initializes a replica set using default parameters.
rs.initiate(replSetcfg)
Initializes a replica set using a configuration description.
rs.add("host:port")
Adds a member server to the replica set with a simple string that provides
hostname and (optionally) a specific port.
rs.add(membercfg)
Adds a member server to the replica set using a configuration description. You
must use this method if you want to specify specific attributes (for example, a
priority for the new member server).
rs.addArb("host:port")
Adds a new member server to operate as an arbiter. The member does not need to
have been started with a --replSet option; any mongod instance running on any
reachable machine can perform this task. Take care that this server is reachable by
all members of the replica set.
rs.stepDown()
Makes the primary server relinquish its role and forces the election of a new
primary server in the cluster when you run this command against the primary
member of a replica set. Note that only active secondary servers are available as
candidates for becoming the new primary server and the original primary may be
re-elected if no other candidate member is available after 60 seconds of waiting.
rs.syncFrom("host:port")
Make a secondary sync from a given member. Can be used to form a sync chain.
rs.freeze(secs)
Freeze a given member and make it ineligible from becoming a primary for the
specified number of seconds.
rs.remove("host:port")
Remove a given member from a replica set.
rs.slaveOk()
Set this connection so that it will allow reads from secondaries.
rs.conf()
Redisplays the configuration structure of the current replica set. This command is
useful for obtaining a configuration structure for a replica set. This configuration
structure can be modified and then supplied to rs.initiate() again to change
the structure's configuration. This technique provides the only supported way to
remove a member server from a replica set; there is currently no direct method
available for doing that.
db.isMaster()
This function is not specific to replica sets; rather, it is a general replication support
function that allows an application or driver to determine whether a particular
connected instance is the master/primary server in a replication topology.
The following sections take a closer look at some of the more commonly used commands listed in Table 11-2 ,
providing additional details about what they do and how to use them.
 
Search WWH ::




Custom Search