This version of the documentation is archived and no longer supported.


On this page


rs.add(host, arbiterOnly)

Adds a member to a replica set.

Parameter Type Description
host string or document The new member to add to the replica set. If a string, specify the hostname and optionally the port number for the new member. If a document, specify a replica-set members document, as found in the members array. To view a replica set’s members array, run rs.conf().
arbiterOnly boolean Optional. Applies only if the <host> value is a string. If true, the added host is an arbiter.”

You may specify new hosts in one of two ways:

  1. as a “hostname” with an optional port number to use the default configuration as in the Add a Member to an Existing Replica Set example.
  2. as a configuration document, as in the Configure and Add a Member example.

rs.add() provides a wrapper around some of the functionality of the “replSetReconfigdatabase command and the corresponding shell helper rs.reconfig(). See the Replica Set Configuration document for full documentation of all replica set configuration options.


rs.add() can in some cases force an election for primary which will disconnect the shell. In such cases, the shell displays an error even if the operation succeeds.


To add a mongod accessible on the default port 27017 running on the host, use the following rs.add() invocation:


If is an arbiter, use the following form:

rs.add('', true)

To add as a secondary-only member of set, use the following form of rs.add():

rs.add( { "_id": 3, "host": "", "priority": 0 } )

Replace, 3 with the next unused _id value in the replica set. See rs.conf() to see the existing _id values in the replica set configuration document.

See the Replica Set Configuration and Replica Set Tutorials documents for more information.