---
title: Adding a member to an existing MongoDB replica set
description: You can add a new node to an existing MongoDB replica set.
component: pingintelligence
version: 5.2
page_id: pingintelligence:pingintelligence_reference_guide:pingintelligence_add_member_to_existing_mongodb
canonical_url: https://docs.pingidentity.com/pingintelligence/5.2/pingintelligence_reference_guide/pingintelligence_add_member_to_existing_mongodb.html
revdate: April 3, 2024
section_ids:
  before-you-begin: Before you begin
  about-this-task: About this task
  steps: Steps
  result: Result:
  next-steps: Next steps
---

# Adding a member to an existing MongoDB replica set

You can add a new node to an existing MongoDB replica set.

## Before you begin

You must have:

* An active replica set.

* A new MongoDB system accessible by the replica set.

* ClusterAdmin privileges.

## About this task

|   |                                                                       |
| - | --------------------------------------------------------------------- |
|   | `absrs01` is the name of the replica set used in the following steps. |

To add a node to an existing replica set:

## Steps

1. Create the MongoDB directory structure on the new MongoDB node:

   ```
   # mkdir -p /opt/pingidentity/mongo/data/opt/pingidentity/mongo/logs \ /opt/pingidentity/mongo/key
   ```

2. Download MongoDB 4.2 on the node and extract it to `/opt/pingidentity/mongo`:

   ```
   # cd /opt/pingidentity/ /opt/pingidentity# wget \ https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-4.2.0.tgz \ -O mongodb.tgz && tar xzf mongodb.tgz -C /opt/pingidentity/mongo/ --strip-components=1
   ```

3. Update the shell path variable and reload the shell:

   ```
   /opt/pingidentity# echo PATH=$PATH:/opt/pingidentity/mongo/bin >> ~/.bashrc; /opt/pingidentity# source ~/.bashrc
   ```

4. Copy the contents of the `/opt/pingidentity/mongo/key` directory from the primary node to the new node into `/opt/pingidentity/mongo/key`.

5. Start the MongoDB database on the new node:

   ```
   /opt/pingidentity# cd mongo /opt/pingidentity/mongo# mongod --auth --dbpath ./data/ --logpath ./logs/mongo.log --port 27017 --replSet absrs01 --fork --keyFile ./key/mongodb-keyfile -bind_ip 0.0.0.0
   ```

6. Connect to the `mongo` shell of the primary node and run the following command:

   ```
   absrs01:PRIMARY> rs.add({"host": "<IP address of new node>:27017", "priority": 2})
   ```

   ### Result:

   The state of the new node changes to `STARTUP2`. This indicates that the synchronization between the replica set and the new node has started.

7. Verify that the new node is added as a secondary node to the replica set using the following command:

   ```
   absrs01:PRIMARY> rs.status()
   ```

## Next steps

For more information, see <https://docs.mongodb.com/manual/tutorial/expand-replica-set/>.
