Docs Menu
Docs Home
/
MongoDB Manual
/ /

Convert a Secondary to an Arbiter

On this page

  • Convert Secondary to Arbiter and Reuse the Port Number
  • Convert Secondary to Arbiter Running on a New Port Number

If you have a secondary in a replica set that no longer needs to hold data but that needs to remain in the set to ensure that the set can elect a primary, you may convert the secondary to an arbiter using either procedure in this tutorial. Both procedures are operationally equivalent:

  • You may operate the arbiter on the same port as the former secondary. In this procedure, you must shut down the secondary and remove its data before restarting and reconfiguring it as an arbiter.

    For this procedure, see Convert Secondary to Arbiter and Reuse the Port Number.

  • Run the arbiter on a new port. In this procedure, you can reconfigure the server as an arbiter before shutting down the instance running as a secondary.

    For this procedure, see Convert Secondary to Arbiter Running on a New Port Number.

Note

For the following MongoDB versions, pv1 increases the likelihood of w:1 rollbacks compared to pv0 (no longer supported in MongoDB 4.0+) for replica sets with arbiters:

  • MongoDB 3.4.1

  • MongoDB 3.4.0

  • MongoDB 3.2.11 or earlier

See Replica Set Protocol Version.

  1. If your application is connecting directly to the secondary, modify the application so that MongoDB queries don't reach the secondary.

  2. Shut down the secondary.

  3. Remove the secondary from the replica set by calling the rs.remove() method. Perform this operation while connected to the current primary in the mongo shell:

    rs.remove("<hostname><:port>")
  4. Verify that the replica set no longer includes the secondary by calling the rs.conf() method in the mongo shell:

    rs.conf()
  5. Move the secondary's data directory to an archive folder. For example:

    mv /data/db /data/db-old

    Note

    Optional

    You may remove the data instead.

  6. Create a new, empty data directory to point to when restarting the mongod instance. You can reuse the previous name. For example:

    mkdir /data/db
  7. Restart the mongod instance for the secondary, specifying the port number, the empty data directory, and the replica set. You can use the same port number you used before. Issue a command similar to the following:

    Warning

    Before binding to a non-localhost (e.g. publicly accessible) IP address, ensure you have secured your cluster from unauthorized access. For a complete list of security recommendations, see Security Checklist. At minimum, consider enabling authentication and hardening network infrastructure.

    mongod --port 27021 --dbpath /data/db --replSet rs --bind_ip localhost,<hostname(s)|ip address(es)>
  8. In the mongo shell convert the secondary to an arbiter using the rs.addArb() method:

    rs.addArb("<hostname><:port>")
  9. Verify the arbiter belongs to the replica set by calling the rs.conf() method in the mongo shell.

    rs.conf()

    The arbiter member should include the following:

    "arbiterOnly" : true
  1. If your application is connecting directly to the secondary or has a connection string referencing the secondary, modify the application so that MongoDB queries don't reach the secondary.

  2. Create a new, empty data directory to be used with the new port number. For example:

    mkdir /data/db-temp
  3. Start a new mongod instance on the new port number, specifying the new data directory and the existing replica set. Issue a command similar to the following:

    Warning

    Before binding to a non-localhost (e.g. publicly accessible) IP address, ensure you have secured your cluster from unauthorized access. For a complete list of security recommendations, see Security Checklist. At minimum, consider enabling authentication and hardening network infrastructure.

    mongod --port 27021 --dbpath /data/db-temp --replSet rs --bind_ip localhost,<hostname(s)|ip address(es)>
  4. In the mongo shell connected to the current primary, convert the new mongod instance to an arbiter using the rs.addArb() method:

    rs.addArb("<hostname><:port>")
  5. Verify the arbiter has been added to the replica set by calling the rs.conf() method in the mongo shell.

    rs.conf()

    The arbiter member should include the following:

    "arbiterOnly" : true
  6. Shut down the secondary.

  7. Remove the secondary from the replica set by calling the rs.remove() method in the mongo shell:

    rs.remove("<hostname><:port>")
  8. Verify that the replica set no longer includes the old secondary by calling the rs.conf() method in the mongo shell:

    rs.conf()
  9. Move the secondary's data directory to an archive folder. For example:

    mv /data/db /data/db-old

    Note

    Optional

    You may remove the data instead.

Back

Configure Non-Voting Replica Set Member